Plotly: How to set the range of the y axis?(Plotly:如何设置y轴的范围?)
问题描述
我有以下代码来使用 Plotly 创建线图.如何将 Y 轴的范围设置为始终在 [0;10]?
更新到新版本
设置图形时,您可以使用 plotly 的
完整代码:
且没有魔法下划线表示法的原始答案:
设置图形时,使用:
或者如果你已经有了一个名为 fig
的图,你可以使用:
剧情:
Jupyter Notebook 的完整代码:
一些重要细节:
通过此设置,您可以轻松添加 y 轴标题,如下所示:
如果您想进一步格式化该标题,这有点更棘手.我发现用 title = go.layout.yaxis.Title(text='y Axis', font=dict(size=14, color='#7f7f7f')
添加另一个元素是最简单的.只要你做对了,你就不应该遇到上面评论中的情况:
谢谢.我尝试过这个.但是我在 yaxis 中有 2 个定义布局:yaxis=dict(range=[0, 10]) 和 yaxis=go.layout.YAxis.所以出现错误.
看看这个:
剧情:
带有 y 轴文本格式的完整代码:
I have the following code to create the line plot with Plotly. How can I set the range of Y axis to always have it in [0; 10]?
Updatefornewerversions
When setting up a figure you can use plotly's magic underscore notation and specify layout_yaxis_range=[<from_value>, <to_value>]
like this:
Or if you've already got a figure named fig
, you can use:
And:
Or:
Figure:
Completecode:
andnomagicunderscorenotation:
When setting up a figure, use:
Or if you've already got a figure named fig
, you can use:
Plot:
Complete code for Jupyter Notebook:
Some important details:
With this setup, you can easily add an y axis title like this:
It's a little more tricky if you'd like to format that title further. I find it easiest to actually add another element with title = go.layout.yaxis.Title(text='y Axis', font=dict(size=14, color='#7f7f7f')
. As long as you do it the right way, you should not experience the situation in your comment above:
Thanks. I tried it. But then I have 2 definitions of yaxis in the Layout: yaxis=dict(range=[0, 10]) and yaxis=go.layout.YAxis. Therefore an error appears.
Take a look at this:
Plot:
Complete code with y-axis text formatting:
这篇关于Plotly:如何设置y轴的范围?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!