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

    1. <tfoot id='YmD3a'></tfoot>

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

    2. <legend id='YmD3a'><style id='YmD3a'><dir id='YmD3a'><q id='YmD3a'></q></dir></style></legend>

        Plotly:如何使用 plotly express 在辅助 y 轴上绘图

        时间:2023-09-28

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

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

                  <bdo id='IfGaO'></bdo><ul id='IfGaO'></ul>
                • 本文介绍了Plotly:如何使用 plotly express 在辅助 y 轴上绘图的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  如何利用 plotly.express 在一个 Pandas 数据框的两个 y 轴上绘制多条线?

                  How do I utilize plotly.express to plot multiple lines on two yaxis out of one Pandas dataframe?

                  我发现这对于绘制包含特定子字符串的所有列非常有用:

                  I find this very useful to plot all columns containing a specific substring:

                      fig = px.line(df, y=df.filter(regex="Linear").columns, render_mode="webgl")
                  

                  因为我不想遍历所有过滤后的列并使用类似的东西:

                  as I don't want to loop over all my filtered columns and use something like:

                      fig.add_trace(go.Scattergl(x=df["Time"], y=df["Linear-"]))
                  

                  在每次迭代中.

                  推荐答案

                  我花了一些时间来解决这个问题,但我觉得这对某些人可能有用.

                  It took me some time to fiddle this out, but I feel this could be useful to some people.

                  # import some stuff
                  import plotly.express as px
                  from plotly.subplots import make_subplots
                  import pandas as pd
                  import numpy as np
                  
                  # create some data
                  df = pd.DataFrame()
                  n = 50
                  df["Time"] = np.arange(n)
                  df["Linear-"] = np.arange(n)+np.random.rand(n)
                  df["Linear+"] = np.arange(n)+np.random.rand(n)
                  df["Log-"] = np.arange(n)+np.random.rand(n)
                  df["Log+"] = np.arange(n)+np.random.rand(n)
                  df.set_index("Time", inplace=True)
                  
                  subfig = make_subplots(specs=[[{"secondary_y": True}]])
                  
                  # create two independent figures with px.line each containing data from multiple columns
                  fig = px.line(df, y=df.filter(regex="Linear").columns, render_mode="webgl",)
                  fig2 = px.line(df, y=df.filter(regex="Log").columns, render_mode="webgl",)
                  
                  fig2.update_traces(yaxis="y2")
                  
                  subfig.add_traces(fig.data + fig2.data)
                  subfig.layout.xaxis.title="Time"
                  subfig.layout.yaxis.title="Linear Y"
                  subfig.layout.yaxis2.type="log"
                  subfig.layout.yaxis2.title="Log Y"
                  # recoloring is necessary otherwise lines from fig und fig2 would share each color
                  # e.g. Linear-, Log- = blue; Linear+, Log+ = red... we don't want this
                  subfig.for_each_trace(lambda t: t.update(line=dict(color=t.marker.color)))
                  subfig.show()
                  

                  技巧

                  subfig.for_each_trace(lambda t: t.update(line=dict(color=t.marker.color)))
                  

                  我是从 nicolaskruchten 那里得到的:https://stackoverflow.com/a/60031260

                  I got from nicolaskruchten here: https://stackoverflow.com/a/60031260

                  这篇关于Plotly:如何使用 plotly express 在辅助 y 轴上绘图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  上一篇:如何在每个波段/bin中以数据百分比作为标签绘制正态分布? 下一篇:Plotly:如何为子图添加边框和侧标签,并同步平移?

                  相关文章

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

                  <tfoot id='wxt7e'></tfoot>
                    <legend id='wxt7e'><style id='wxt7e'><dir id='wxt7e'><q id='wxt7e'></q></dir></style></legend>

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

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