<legend id='RvEll'><style id='RvEll'><dir id='RvEll'><q id='RvEll'></q></dir></style></legend>

<tfoot id='RvEll'></tfoot>
          <bdo id='RvEll'></bdo><ul id='RvEll'></ul>
      1. <small id='RvEll'></small><noframes id='RvEll'>

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

        从下拉菜单或按钮 Python/Plotly 将 sqrt 设置为 yaxis 比例

        Set sqrt as yaxis scale from dropdown or button-Python/Plotly(从下拉菜单或按钮 Python/Plotly 将 sqrt 设置为 yaxis 比例)
        <i id='jjKEE'><tr id='jjKEE'><dt id='jjKEE'><q id='jjKEE'><span id='jjKEE'><b id='jjKEE'><form id='jjKEE'><ins id='jjKEE'></ins><ul id='jjKEE'></ul><sub id='jjKEE'></sub></form><legend id='jjKEE'></legend><bdo id='jjKEE'><pre id='jjKEE'><center id='jjKEE'></center></pre></bdo></b><th id='jjKEE'></th></span></q></dt></tr></i><div id='jjKEE'><tfoot id='jjKEE'></tfoot><dl id='jjKEE'><fieldset id='jjKEE'></fieldset></dl></div>
            1. <small id='jjKEE'></small><noframes id='jjKEE'>

                <tbody id='jjKEE'></tbody>
                <legend id='jjKEE'><style id='jjKEE'><dir id='jjKEE'><q id='jjKEE'></q></dir></style></legend>
              1. <tfoot id='jjKEE'></tfoot>
                  <bdo id='jjKEE'></bdo><ul id='jjKEE'></ul>
                  本文介绍了从下拉菜单或按钮 Python/Plotly 将 sqrt 设置为 yaxis 比例的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  从这里的示例:

                  但您实际上不必为了更改与 y 轴关联的数据来显示给定系列的平方根.下面的完整片段生成了一个图形,您可以轻松地在显示原始数据和平方根序列之间切换.

                  图 1:原始数据

                  情节 2:np.sqrt

                  完整代码:

                  将 numpy 导入为 np导入 plotly.graph_objects将 plotly.express 导入为 pxdf = px.data.gapminder().query("year == 2007")# 图形设置fig = go.Figure()fig.add_scatter(mode="markers", x=df["gdpPercap"], y=df["lifeExp"])fig.add_scatter(mode="markers", x=df["gdpPercap"], y=np.sqrt(df["lifeExp"]), visible = False)# 更新菜单按钮按钮 = [dict(method='restyle',标签='线性',可见=真,args=[{'label': '线性','可见':[真,假],}]),dict(method='restyle',标签='sqrt',可见=真,args=[{'label': '线性','可见':[假,真],}])]# 指定更新菜单嗯 = [{'按钮':按钮,方向":向下"}]fig.update_layout(updatemenus=um)# fig.update_yaxes(type="log")图.show()

                  From this example here : Set linear or log axes from button or dropdown menu I can use a button to change the yaxis from linear to log. However i need to change it to sqrt.

                  I have looked at from Plotly: reference layout axis I have found that there is no type ("sqrt")

                  type Code: fig.update_yaxes(type=) Type: enumerated , one of ( "-" | "linear" | "log" | "date" | "category" | "multicategory" ) Default: "-" Sets the axis type. By default, plotly attempts to determined the axis type by looking into the data of the traces that referenced the axis in question.

                  Here is the exmaple code:

                  import plotly.graph_objects as go
                  
                  fig = go.Figure()
                  
                  fig.add_trace(go.Scatter(
                      x=[0, 1, 2, 3, 4, 5, 6, 7, 8],
                      y=[8, 7, 6, 5, 4, 3, 2, 1, 0]
                  ))
                  
                  fig.add_trace(go.Scatter(
                      x=[0, 1, 2, 3, 4, 5, 6, 7, 8],
                      y=[0, 1, 2, 3, 4, 5, 6, 7, 8]
                  ))
                  
                  fig.update_layout(title_text="CIR plot ",
                                            updatemenus=[
                              dict(
                                   buttons=list([
                                       dict(label="Linear",  method="update", args=[{"yaxis":{"type": "linear"}}]),
                                       dict(label="Log", method="update", args=[{"yaxis":{"type": "log"}}]),
                                                    ]),
                              )])
                  
                   #UPDATE Y AXIS HERE
                  fig.update_layout( updatemenus=[
                              dict(
                                   buttons=list([
                                       dict(label="Linear-ID",  
                                            method="relayout", 
                                            args=[{"yaxis.type": "linear"}]),
                                       dict(label="Log-ID", 
                                            method="relayout", 
                                            args=[{"yaxis.type": "log"}]),
                                                    ]),
                              )])
                  fig.show()
                  

                  Is there a way to use a button to update the scale to sqrt ?

                  解决方案

                  To my knowledge there's currently no way to specify sqrt as scale for the axis that would trigger a visual change to the axis labels like the case is for fig.update_xaxes(type="log"):

                  But you don't really have to in order to change the data associated with the yaxis to display the square roots of a given series. The complete snippet below produce a figure that will easily let you switch between displaying the raw data and a series with square roots.

                  Plot 1: Raw data

                  Plot 2: np.sqrt

                  Complete code:

                  import numpy as np
                  import plotly.graph_objects as go
                  import plotly.express as px
                  df = px.data.gapminder().query("year == 2007")
                  
                  # figure setup
                  fig = go.Figure()
                  fig.add_scatter(mode="markers", x=df["gdpPercap"], y=df["lifeExp"])
                  fig.add_scatter(mode="markers", x=df["gdpPercap"], y=np.sqrt(df["lifeExp"]), visible = False)
                  
                  # buttons for updatemenu
                  buttons = [dict(method='restyle',
                                  label='linear',
                                  visible=True,
                                  args=[{'label': 'linear',
                                         'visible':[True, False],
                                        }
                                       ]),
                             dict(method='restyle',
                                  label='sqrt',
                                  visible=True,
                                  args=[{'label': 'linear',
                                         'visible':[False, True],
                                        }
                                       ])]
                             
                  # specify updatemenu        
                  um = [{'buttons':buttons,
                        'direction': 'down'}
                        ]
                  
                  fig.update_layout(updatemenus=um)
                  # fig.update_yaxes(type="log")
                  fig.show()
                  

                  这篇关于从下拉菜单或按钮 Python/Plotly 将 sqrt 设置为 yaxis 比例的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  本站部分内容来源互联网,如果有图片或者内容侵犯了您的权益,请联系我们,我们会在确认后第一时间进行删除!

                  相关文档推荐

                  Adding config modes to Plotly.Py offline - modebar(将配置模式添加到 Plotly.Py 离线 - 模式栏)
                  Plotly: How to style a plotly figure so that it doesn#39;t display gaps for missing dates?(Plotly:如何设置绘图图形的样式,使其不显示缺失日期的间隙?)
                  python save plotly plot to local file and insert into html(python将绘图保存到本地文件并插入到html中)
                  Plotly: What color cycle does plotly express follow?(情节:情节表达遵循什么颜色循环?)
                  How to save plotly express plot into a html or static image file?(如何将情节表达图保存到 html 或静态图像文件中?)
                  Plotly: How to make a line plot from a pandas dataframe with a long or wide format?(Plotly:如何使用长格式或宽格式的 pandas 数据框制作线图?)

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

                            <bdo id='gCSfm'></bdo><ul id='gCSfm'></ul>

                            <legend id='gCSfm'><style id='gCSfm'><dir id='gCSfm'><q id='gCSfm'></q></dir></style></legend>