Plotly Express Timeline离散颜色映射异常问题求助
Plotly Express Timeline 分类颜色映射异常问题
我正在用plotly.express.timeline绘制时间线,初始代码如下:
display(plot_df) # Note that start and end time dates are not used
数据包含start_date(日期类型)、start_time/end_time(时间类型)、category(数值型分类数据)列。
fig1 = px.timeline(plot_df, x_start='start_time', x_end='end_time', y='start_date', color='category') fig1.show()
此时绘图正常,但category列的颜色映射被识别为连续型,而该列实际是分类数据。
于是我将category列转为字符串类型后重新绘图:
plot_df['category'] = plot_df['category'].astype(str) fig2 = px.timeline(plot_df, x_start='start_time', x_end='end_time', y='start_date', color='category') fig2.show()
图表出现明显异常,颜色映射完全不符合预期。
此外,使用不同数据子集时也会产生奇怪结果,示例代码如下:
plot_df2 = plot_df[plot_df['start_date'] > pd.to_datetime('2019-05-24')] fig3 = px.timeline(plot_df2, x_start='start_time', x_end='end_time', y='start_date', color='category') fig3.show()
图表同样出现异常的颜色映射问题。
更换可视化环境后问题依旧,请问这是什么原因?
内容的提问来源于stack exchange,提问作者sihen
相关产品推荐
相关产品推荐

