【发布时间】:2020-09-17 02:47:11
【问题描述】:
我正在创建一个条形图,其中包含每个邮政编码的前 10 个最高金额。我已将邮政编码转换为字符串,但在条形图中,x 轴显示为 int 20K、50K 等。在检查邮政编码的 astype 时,它返回对象类型而不是字符串。我糊涂了。 如何在 x 轴上显示邮政编码(即“95519”、“47905”、“44720”)?
Data Set is as follows
zip code index
54 95519 1.70
61 81212 1.70
160 47905 1.70
421 57201 1.70
208 1930 1.69
366 44720 1.69
298 28401 1.68
532 82214 1.68
102 30165 1.67
125 50501 1.67
df3 = df2[['zip code', 'index']]
df3 = df3.nlargest(10, 'index')
df3['zip code'] = df3[['zip code']].astype(str)
fig = px.bar(df3, x='zip code', y='index',
hover_data=['zip code', 'index'], color='index',
labels={'index':'INDEX'}, height=400)
【问题讨论】:
-
你能提供一个 df3 的最小例子吗?可能是
df3.head(),还是df3.head().to_dict()?px.bar-px是什么?请阅读minimal reproducible example。 -
我添加了 df3 的数据集。 px.bar 是快递。 (即导入 plotly.express 作为 px)。我也使用过 grah 对象,但遇到了同样的问题。导入 plotly.graph_objects
标签: python plotly-dash