I’m creating a time_series plot using ggploty and uploading it to the web using plotly. However, when I upload the plot the x axis becomes random numbers like 18.7k and not the dates. Has anyone had any experience with this.
This is how the time comes up:
0 2022-01-04
1 2022-01-03
2 2022-01-02
3 2022-01-01
4 2021-12-31
295 2021-03-15
296 2021-03-14
297 2021-03-13
298 2021-03-12
299 2021-03-11
Name: date, Length: 300, dtype: object
This is my code:
data = pd.DataFrame(json.loads(response.text), columns=[‘unix’, ‘low’, ‘high’, ‘open’, ‘close’, ‘volume’])
data[‘date’] = pd.to_datetime(data[‘unix’], unit=‘s’) # convert to a readable date
data[‘vol_fiat’] = data[‘volume’] * data[‘close’] # multiply the BTC volume by closing price to approximate fiat volume
# data[‘date’] = pd.to_datetime(data[‘date’],format = “%Y-%m-%d”)
data[‘date’] = data[‘date’].dt.strftime("%Y-%m-%d")
print(data[‘date’])
# print(data[data[‘date’] > ‘2021-12-20’])
if data is None:
print(“Did not return any data from Coinbase for this symbol”)
else:
# [data[‘date’] > ‘2021-11-20’]
plot = ggplot(data) + aes(x = ‘date’, y = “close”) + ggtitle(“Price History of %s” %(symbol))+ labs(y = “Market Price”, x = “Timestamp”) + scale_x_date() + geom_line(color=‘blue’, size = 2) + theme(axis_text_x = element_text(angle = 45))
plot = ggplotly(plot.draw())
plot.update_layout(
height = 500,
width = 1000,
margin=dict(l=20, r=20, t=20, b=20),
paper_bgcolor=“LightSteelBlue”,
)
# plot.update_xaxes(range=[‘2021-12-20’, ‘2022-01-01’])
display_chart = pyo.offline.plot(plot, include_plotlyjs =True, output_type = 'div')
display_chart_jinja = Markup(display_chart)
return render_template("index.html", chart = display_chart_jinja, user = current_user)