Python 如何更改y轴步长?
这是我的代码:Python 如何更改y轴步长?,python,plotly,Python,Plotly,这是我的代码: from plotly import graph_objs as go import numpy as np import os from plotly.subplots import make_subplots fig = make_subplots(rows=2, cols=1) # Table product views fig.add_trace( go.Table( header=dict(values=["Period",
from plotly import graph_objs as go
import numpy as np
import os
from plotly.subplots import make_subplots
fig = make_subplots(rows=2, cols=1)
# Table product views
fig.add_trace(
go.Table(
header=dict(values=["Period", "Views"]),
cells=dict(values=[
[
"01/09/2019 - 07/09/2019",
"08/09/2019 - 14/09/2019",
"15/09/2019 - 21/09/2019",
"22/09/2019 - 28/09/2019"
],
[15, 25, 35, 32]
])
)
)
# Chart product views
fig.add_trace(
go.Bar(
x=[
"01/09/2019 - 07/09/2019",
"08/09/2019 - 14/09/2019",
"15/09/2019 - 21/09/2019",
"22/09/2019 - 28/09/2019"
],
y=[15, 25, 35, 32],
),
row=2,
col=1
)
if not os.path.exists("files"):
os.mkdir("files")
fig.update_yaxes(title_text="Product views", range=[0, 40], row=2, col=1)
fig.update_layout(height=600, width=600, title_text="<b>Library Shelving</b> statistic")
fig.write_image("files/statistic.pdf")
它呈现一个表格和一个条形图。在条形图Y轴上,步骤如下所示:
30,25,20,15,10,5,0.
我如何显示其余的数字?或者至少让步骤2而不是步骤5。例如30、28、26、24等
当前绘图:
您可以使用dtick参数:您可以使用dtick参数:只需在图中设置dtick=2。更新如下:
片段1
图1:
这使得情节有点奇怪,所以我也将你的高度调整为800:
片段2:
地块2:
只需在图中设置dtick=2,如下所示:
片段1
图1:
这使得情节有点奇怪,所以我也将你的高度调整为800:
片段2:
地块2:
fig.update_yaxes(title_text="Product views", range=[0, 40], row=2, col=1, dtick=2)
fig.update_layout(height=800, width=600, title_text="<b>Library Shelving</b> statistic")