Plotly Graph不能正确显示X轴值
考虑以下代码:
from plotly import graph_objs as go
import pandas as pd
mtds = ['2022-03', '2022-04', '2022-05', '2022-06']
values = [28, 24, 20, 18]
data1 = []
for j in range(4):
data1.append([mtds[j], values[j]])
df1 = pd.DataFrame(data1, columns=['month', 'counts'])
fig = go.Figure()
fig.add_trace(go.Scatter(
x = df1['month'],
y = df1['counts'],
name = 'counts history'
))
fig.show()
输出为
我想修改代码,以便 X轴而不是日期中显示了MTDS列表字符串值'2022-03','2022-04','2022-05','2022-06'。你能协助这一点吗?
谢谢。
Consider the following code :
from plotly import graph_objs as go
import pandas as pd
mtds = ['2022-03', '2022-04', '2022-05', '2022-06']
values = [28, 24, 20, 18]
data1 = []
for j in range(4):
data1.append([mtds[j], values[j]])
df1 = pd.DataFrame(data1, columns=['month', 'counts'])
fig = go.Figure()
fig.add_trace(go.Scatter(
x = df1['month'],
y = df1['counts'],
name = 'counts history'
))
fig.show()
The output is
However, this is not was I was expecting. I would like to amend the code such that
the mtds list string values '2022-03', '2022-04', '2022-05', '2022-06' are shown in the x-axis instead of the dates. Could you please assist with this ?
Thank you.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
根据
plotly
document 在时间序列上,您可以使用update_xaxes
更改X轴标签的出现和格式的方法:As per the
plotly
documentation on time series, you can use theupdate_xaxes
method to change the ocurrence and format of the x-axis labels: