Ask coding questions

← Back to all posts
how can we save a fig to display as a image
Harpreet14

when I save plt.savefig('saved_figure.png') I can't see it in order to display it as an image.

def previous_price(crypto,currency,periods):

crypto_url= 'https://api.cryptowat.ch/markets/bitfinex/'+ crypto+currency+'/ohlc'

resp = requests.get(crypto_url, params={
'periods': periods
})
data = resp.json()
df = pd.DataFrame(data['result'], columns=[
'CloseTime', 'OpenPrice', 'HighPrice', 'LowPrice', 'ClosePrice', 'Volume', 'NA'
])
df.drop(columns=['NA'], inplace=True)

df['CloseTime'] = pd.to_datetime(df['CloseTime'], unit='s')

#df.set_index('CloseTime', inplace=True)
closetime=df[['CloseTime']].copy()
price = df[['ClosePrice']].copy()
print(price.head())

plt.figure(figsize=(6,6))
plt.plot(closetime,price)
plt.show()
plt.savefig('saved_figure.png')

previous_price('btc','usd','3600')

Voters
Harpreet14