First time here? Check out the FAQ!

Ask Your Question
1

list_plot only showing one axis

asked 4 years ago

GeheimAgent gravatar image

I'm trying to plot price series from Yahoo Finance using list_plot, however it only plots the values on x-axis, when it would be on the y-axis. I tried using list_plot(prices) and making tuples of (x,price). Please see the following code:

import json
import requests

simb = 'IRBR3'
js = '********query1.finance.yahoo.com/v8/finance/chart/' + simb + '.SA?symbol=' + simb + '.SA&period1=0&period2=9999999999&interval=1d'  #please modify the asterisks to correct the https link, not enough karma to publish links :-(

response = requests.get(js)
yf = json.loads(response.text)
prices=yf['chart']['result'][0]['indicators']['adjclose'][0]['adjclose']
#list_plot(prices)     #doesn't work
#pts = [(float(x),y) for x in range(len(prices)-1) for y in prices]
pts=list(zip(range(len(prices)-1),prices))
list_plot(pts)    #doesn't work either

Is there any configuration lacking? Or maybe a "data mistyping"?

Preview: (hide)

1 Answer

Sort by » oldest newest most voted
2

answered 4 years ago

rburing gravatar image

De lijst prices lijkt een aantal keer None te bevatten, waardoor er iets misgaat in list_plot (weet niet precies waarom). Als je deze eruit filtert, bijvoorbeeld door ze op nul te zetten,

prices = [p if p is not None else 0 for p in prices]

dan lukt het wel:

list_plot(prices)

list_plot

Preview: (hide)
link

Comments

Thank you for your help. I didn't check the values returned in prices, albeit I have not expected such plot behavior.

GeheimAgent gravatar imageGeheimAgent ( 4 years ago )

@GeheimAgent Indeed it is a very odd bug; I just reported it as trac ticket #29960 (with an explanation of why it happens).

rburing gravatar imagerburing ( 4 years ago )

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools

1 follower

Stats

Asked: 4 years ago

Seen: 344 times

Last updated: Jun 23 '20