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

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

      1. <legend id='gfpq2'><style id='gfpq2'><dir id='gfpq2'><q id='gfpq2'></q></dir></style></legend>

      2. <tfoot id='gfpq2'></tfoot>
      3. Plotly:将线添加到条形图

        时间:2023-09-28
          <tbody id='pihXE'></tbody>

            <tfoot id='pihXE'></tfoot>
          1. <small id='pihXE'></small><noframes id='pihXE'>

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

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

                • 本文介绍了Plotly:将线添加到条形图的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  我有一个来自数据框的绘图条形图:

                  I have a plotly bar chart, from a dataframe:

                  fig = df.iplot(asFigure=True, kind='bar', barmode = 'relative')
                  py.iplot(fig)
                  

                  是否可以将数据框中的一列变成一行?

                  Is it possible to turn one of the columns in the data frame into a line series?

                  推荐答案

                  评论中的建议链接确实有一些有价值的资源,但他们不会直接回答您的问题.iplot() 使用 pandas 数据框作为输入,并生成堆叠条形图.这是一种可以让您完全做到这一点的方法,尽管不使用 df.iplot()

                  The suggested link in the comments does have some valuable resources, but they won't answer your questions directly. iplot() uses a pandas dataframe as input, and produces a stacked barplot. Here's an approach that will let you do exactly that, albeit without using df.iplot()

                  一、剧情:

                  现在,代码

                  我的建议基于以下示例:plot.ly/pandas/bar-charts.正如您将看到的,这是一个基于 pandas 数据框的示例 - 就像 df.iplot().您可以简单地从堆叠条中取出一个系列或跟踪",并通过更改将其显示为一条线

                  My suggestion builds on an example found at: plot.ly/pandas/bar-charts. As you'll see that's an example that builds on a pandas dataframe - just like df.iplot(). You can simply take a series or 'trace' out of the stacked bars and display it as a line by changing

                  go.Bar(x=df['x'],
                         y=df['y4'])
                  

                  到:

                   go.Scatter(x=df['x'],
                              y=df['y4'])
                  

                  我还添加了一些元素,以便更轻松地在 Jupyter 笔记本中离线显示结果.另请注意,我已将最后一行从 py.iplot(fig, filename='pandas-bar-chart-layout') 更改为 iplot(fig, filename='pandas-条形图布局')

                  I've also added a few elements to make it easier to display your results offline in a Jupyter notebook. Also note that I've changed the last line from py.iplot(fig, filename='pandas-bar-chart-layout') to just iplot(fig, filename='pandas-bar-chart-layout')

                  完整片段:

                  import plotly.plotly as py
                  import plotly.graph_objs as go
                  from plotly.offline import download_plotlyjs, init_notebook_mode, plot, iplot
                  
                  init_notebook_mode(connected=True)
                  
                  import pandas as pd
                  import numpy as np
                  
                  N = 20
                  x = np.linspace(1, 10, N)
                  y = np.random.randn(N)+3
                  y2 = np.random.randn(N)+6
                  y3 = np.random.randn(N)+9
                  y4 = np.random.randn(N)+12
                  df = pd.DataFrame({'x': x, 'y': y, 'y2':y2, 'y3':y3, 'y4':y4})
                  df.head()
                  
                  data = [
                      go.Bar(
                          x=df['x'], # assign x as the dataframe column 'x'
                          y=df['y']
                      ),
                      go.Bar(
                          x=df['x'],
                          y=df['y2']
                      ),
                      go.Bar(
                          x=df['x'],
                          y=df['y3']
                      ),
                      go.Scatter(
                          x=df['x'],
                          y=df['y4']
                      )
                  
                  ]
                  
                  layout = go.Layout(
                      barmode='stack',
                      title='Stacked Bar with Pandas'
                  )
                  
                  fig = go.Figure(data=data, layout=layout)
                  
                  # IPython notebook
                  iplot(fig, filename='pandas-bar-chart-layout')
                  

                  这篇关于Plotly:将线添加到条形图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  上一篇:Plotly:如何在桑基图中设置节点位置? 下一篇:Plotly:如何使用 updatemenus 更新一个特定的跟踪?

                  相关文章

                    • <bdo id='dIirn'></bdo><ul id='dIirn'></ul>
                  1. <small id='dIirn'></small><noframes id='dIirn'>

                    <tfoot id='dIirn'></tfoot>

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

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