python - Plotly:订购甘特图以在左上角而不是左下角显示最早的项目
问题描述
我正在尝试使用 plotly 制作一个简单的甘特图,但由于某种原因,最早的项目显示在左下角,而不是应该的左上角。
有没有办法改变这个?该示例来自以下文档(已修复,因此可以运行):
import plotly.figure_factory as ff
df = [dict(Task="Job A", Start='2009-01-01',
Finish='2009-02-28', Complete=10),
dict(Task="Job B", Start='2009-03-05',
Finish='2009-04-15', Complete=60),
dict(Task="Job C", Start='2009-02-20',
Finish='2009-05-30', Complete=95)]
fig = ff.create_gantt(df, colors='Blues', index_col='Complete',
show_colorbar=True, bar_width=0.5,
showgrid_x=True, showgrid_y=True)
fig.show()
我们将忽略 showgrid 似乎不起作用。这是因为默认颜色是白底白字。
解决方案
import plotly.figure_factory as ff
df = [dict(Task='Job A', Start='2009-01-01', Finish='2009-02-28', Complete=10),
dict(Task='Job B', Start='2009-03-05', Finish='2009-04-15', Complete=60),
dict(Task='Job C', Start='2009-02-20', Finish='2009-05-30', Complete=95)]
fig = ff.create_gantt(df, colors='Blues', index_col='Complete', show_colorbar=True,
bar_width=0.5, showgrid_x=True, showgrid_y=True)
fig.update_layout(plot_bgcolor='white', # change the plot background color
yaxis=dict(autorange='reversed', # reverse the order of the y-axis tick labels
linecolor='gray', # change the color of the y-axis line
gridcolor='gray'), # change the color of the y-axis grid lines
xaxis=dict(linecolor='gray', # change the color of the x-axis line
gridcolor='gray')) # change the color of the x-axis grid lines
fig.show()
推荐阅读
- scala - 如何为 scala 对象编写 scalatest 单元测试?
- sql - 在 SQL 中对具有多种数据类型的列求和
- python - python解码非英语用作url?
- xaml - 如何在 UNO UWP 中设置背景图像?
- php - 警告:key() 期望参数 1 是数组,给定字符串
- vue.js - 如何从父组件观察子属性的变化
- spring-mvc - org.springframework.security.core.userdetails.User 不能转换为 MyUserDetails (Junit 5)
- mdx - 你能帮我处理这个 MDX 查询吗?
- flask - 多行在烧瓶模板的VS代码中连接成一行
- javascript - 如何设置 Observable.fromEvent 以处理 jQuery 过滤事件