• <legend id='ciXIu'><style id='ciXIu'><dir id='ciXIu'><q id='ciXIu'></q></dir></style></legend>
    <tfoot id='ciXIu'></tfoot>
      <bdo id='ciXIu'></bdo><ul id='ciXIu'></ul>

      1. <i id='ciXIu'><tr id='ciXIu'><dt id='ciXIu'><q id='ciXIu'><span id='ciXIu'><b id='ciXIu'><form id='ciXIu'><ins id='ciXIu'></ins><ul id='ciXIu'></ul><sub id='ciXIu'></sub></form><legend id='ciXIu'></legend><bdo id='ciXIu'><pre id='ciXIu'><center id='ciXIu'></center></pre></bdo></b><th id='ciXIu'></th></span></q></dt></tr></i><div id='ciXIu'><tfoot id='ciXIu'></tfoot><dl id='ciXIu'><fieldset id='ciXIu'></fieldset></dl></div>
      2. <small id='ciXIu'></small><noframes id='ciXIu'>

        Plotly:如何设置y轴的范围?

        时间:2023-09-28

          • <tfoot id='v2szt'></tfoot>

            <small id='v2szt'></small><noframes id='v2szt'>

              <tbody id='v2szt'></tbody>
            • <legend id='v2szt'><style id='v2szt'><dir id='v2szt'><q id='v2szt'></q></dir></style></legend>

                <bdo id='v2szt'></bdo><ul id='v2szt'></ul>
                <i id='v2szt'><tr id='v2szt'><dt id='v2szt'><q id='v2szt'><span id='v2szt'><b id='v2szt'><form id='v2szt'><ins id='v2szt'></ins><ul id='v2szt'></ul><sub id='v2szt'></sub></form><legend id='v2szt'></legend><bdo id='v2szt'><pre id='v2szt'><center id='v2szt'></center></pre></bdo></b><th id='v2szt'></th></span></q></dt></tr></i><div id='v2szt'><tfoot id='v2szt'></tfoot><dl id='v2szt'><fieldset id='v2szt'></fieldset></dl></div>
                  本文介绍了Plotly:如何设置y轴的范围?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  我有以下代码来使用 Plotly 创建线图.如何将 Y 轴的范围设置为始终在 [0;10]?

                  layout = go.Layout(标题=go.layout.Title(文本=测试",外部参照='纸',x=0),xaxis=go.layout.XAxis(滴答模式='线性',滴答字体=字典(大小=10),标题=go.layout.xaxis.Title(字体=字典(尺寸=14,颜色='#7f7f7f'))),yaxis=go.layout.YAxis(标题=go.layout.yaxis.Title(文本=y,字体=字典(尺寸=14,颜色='#7f7f7f'))))数据 = [go.Scatter(x=x1, y=y1)]

                  解决方案

                  更新到新版本

                  设置图形时,您可以使用 plotly 的

                  完整代码:

                  # 导入将熊猫导入为 pd导入 plotly.graph_objs将 numpy 导入为 np# 数据np.random.seed(4)x = np.linspace(0, 1, 50)y = np.cumsum(np.random.randn(50))# 绘制折线图fig = go.Figure(data=go.Scatter(x=x, y=y, mode='lines'), layout_yaxis_range=[-4,4])fig.update_layout(yaxis_range=[-4,4])图.show()


                  使用 plotly.offlineiplot 且没有魔法下划线表示法的原始答案:

                  设置图形时,使用:

                  layout = go.Layout(yaxis=dict(range=[fromValue, toValue])

                  或者如果你已经有了一个名为 fig 的图,你可以使用:

                  fig.update_layout(yaxis=dict(range=[fromValue,toValue]))

                  剧情:

                  Jupyter Notebook 的完整代码:

                  # 导入从 plotly.offline 导入 download_plotlyjs, init_notebook_mode, plot, iplot将熊猫导入为 pd导入 plotly.graph_objs将 numpy 导入为 np# 设置init_notebook_mode(连接=真)# 数据np.random.seed(4)x = np.linspace(0, 1, 50)y = np.cumsum(np.random.randn(50))# 线跟踪 = go.Scatter(x=x,y=y,)# 布局布局 = go.Layout(yaxis=dict(range=[-4,4]))# 阴谋fig = go.Figure(data=[trace], layout=layout)iplot(无花果)

                  一些重要细节:

                  通过此设置,您可以轻松添加 y 轴标题,如下所示:

                  # 布局layout = go.Layout(yaxis=dict(range=[-4,4]), title='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 轴文本格式的完整代码:

                  # 导入从 plotly.offline 导入 download_plotlyjs, init_notebook_mode, plot, iplot将熊猫导入为 pd导入 plotly.graph_objs将 numpy 导入为 np# 设置init_notebook_mode(连接=真)# 数据np.random.seed(4)x = np.linspace(0, 1, 50)y = np.cumsum(np.random.randn(50))# 线跟踪 = go.Scatter(x=x,y=y,)# 布局布局=去.布局(yaxis=dict(范围=[-4,4],title = go.layout.yaxis.Title(text='y 轴', font=dict(size=14, color='#7f7f7f'))))# 阴谋fig = go.Figure(data=[trace], layout=layout)iplot(无花果)

                  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]?

                  layout = go.Layout(
                          title=go.layout.Title(
                              text="Test",
                              xref='paper',
                              x=0
                          ),
                          xaxis=go.layout.XAxis(
                              tickmode='linear',
                              tickfont=dict(
                                  size=10
                              ),
                              title=go.layout.xaxis.Title(
                                  font=dict(
                                      size=14,
                                      color='#7f7f7f'
                                  )
                              )
                          ),
                          yaxis=go.layout.YAxis(
                              title=go.layout.yaxis.Title(
                                  text=y,
                                  font=dict(
                                      size=14,
                                      color='#7f7f7f'
                                  )
                              )
                          )
                      )
                  
                      data = [go.Scatter(x=x1, y=y1)]
                  

                  解决方案

                  Update for newer versions

                  When setting up a figure you can use plotly's magic underscore notation and specify layout_yaxis_range=[<from_value>, <to_value>] like this:

                  fig = go.Figure(data=go.Scatter(x=x, y=y, mode='lines'), layout_yaxis_range=[-4,4])
                  

                  Or if you've already got a figure named fig, you can use:

                  fig.update_layout(yaxis_range=[-4,4])
                  

                  And:

                  fig.update(layout_yaxis_range = [-4,4])
                  

                  Or:

                  fig.update_yaxes(range = [-4,4])
                  

                  Figure:

                  Complete code:

                  # imports
                  import pandas as pd
                  import plotly.graph_objs as go
                  import numpy as np
                  
                  # data
                  np.random.seed(4)
                  x = np.linspace(0, 1, 50)
                  y = np.cumsum(np.random.randn(50))
                  
                  # plotly line chart
                  fig = go.Figure(data=go.Scatter(x=x, y=y, mode='lines'), layout_yaxis_range=[-4,4])
                                 
                  fig.update_layout(yaxis_range=[-4,4])
                  fig.show()
                  


                  Original answer using plotly.offline, iplot and no magic underscore notation:

                  When setting up a figure, use:

                  layout = go.Layout(yaxis=dict(range=[fromValue, toValue])
                  

                  Or if you've already got a figure named fig, you can use:

                  fig.update_layout(yaxis=dict(range=[fromValue,toValue]))
                  

                  Plot:

                  Complete code for Jupyter Notebook:

                  # imports
                  from plotly.offline import download_plotlyjs, init_notebook_mode, plot, iplot
                  import pandas as pd
                  import plotly.graph_objs as go
                  import numpy as np
                  
                  # setup
                  init_notebook_mode(connected=True)
                  
                  # data
                  np.random.seed(4)
                  x = np.linspace(0, 1, 50)
                  y = np.cumsum(np.random.randn(50))
                  
                  # line
                  trace = go.Scatter(
                      x=x,
                      y=y,
                  )
                  
                  # layout
                  layout = go.Layout(yaxis=dict(range=[-4,4])
                  )
                  
                  # Plot
                  fig = go.Figure(data=[trace], layout=layout)
                  iplot(fig)
                  

                  Some important details:

                  With this setup, you can easily add an y axis title like this:

                  # layout
                  layout = go.Layout(yaxis=dict(range=[-4,4]), title='y Axis')
                  )
                  

                  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:

                  # imports
                  from plotly.offline import download_plotlyjs, init_notebook_mode, plot, iplot
                  import pandas as pd
                  import plotly.graph_objs as go
                  import numpy as np
                  
                  # setup
                  init_notebook_mode(connected=True)
                  
                  # data
                  np.random.seed(4)
                  x = np.linspace(0, 1, 50)
                  y = np.cumsum(np.random.randn(50))
                  
                  # line
                  trace = go.Scatter(
                      x=x,
                      y=y,
                  )
                  
                  # layout
                  layout = go.Layout(
                      yaxis=dict(range=[-4,4],
                      title = go.layout.yaxis.Title(text='y Axis', font=dict(size=14, color='#7f7f7f')))
                  )
                  
                  # Plot
                  fig = go.Figure(data=[trace], layout=layout)
                  iplot(fig)
                  

                  这篇关于Plotly:如何设置y轴的范围?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  上一篇:在 plotly 中添加索引作为下拉菜单 下一篇:如何隐藏 plotly yaxis 标题(在 python 中)?

                  相关文章

                1. <i id='Dl6Mr'><tr id='Dl6Mr'><dt id='Dl6Mr'><q id='Dl6Mr'><span id='Dl6Mr'><b id='Dl6Mr'><form id='Dl6Mr'><ins id='Dl6Mr'></ins><ul id='Dl6Mr'></ul><sub id='Dl6Mr'></sub></form><legend id='Dl6Mr'></legend><bdo id='Dl6Mr'><pre id='Dl6Mr'><center id='Dl6Mr'></center></pre></bdo></b><th id='Dl6Mr'></th></span></q></dt></tr></i><div id='Dl6Mr'><tfoot id='Dl6Mr'></tfoot><dl id='Dl6Mr'><fieldset id='Dl6Mr'></fieldset></dl></div>

                      • <bdo id='Dl6Mr'></bdo><ul id='Dl6Mr'></ul>
                    1. <legend id='Dl6Mr'><style id='Dl6Mr'><dir id='Dl6Mr'><q id='Dl6Mr'></q></dir></style></legend>
                    2. <small id='Dl6Mr'></small><noframes id='Dl6Mr'>

                      <tfoot id='Dl6Mr'></tfoot>