<tfoot id='9WWYC'></tfoot>

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

      <small id='9WWYC'></small><noframes id='9WWYC'>

      1. Python Plotly - 为散点图和条形图对齐 Y 轴

        Python Plotly - Align Y Axis for Scatter and Bar(Python Plotly - 为散点图和条形图对齐 Y 轴)
          1. <legend id='z5NID'><style id='z5NID'><dir id='z5NID'><q id='z5NID'></q></dir></style></legend>
            <tfoot id='z5NID'></tfoot>

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

              <tbody id='z5NID'></tbody>

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

                  本文介绍了Python Plotly - 为散点图和条形图对齐 Y 轴的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  我正在尝试使用 Scatter 和 Graph 元素创建一个绘图图.一切都很顺利,但有一个问题 - 两个 Y 轴不围绕 0 对齐.

                  I'm trying to create a plotly graph with a Scatter and Graph elements. It all goes nicely, but one issue - the two Y axis don't align around 0.

                  我尝试过使用不同的属性,例如 'mirror' 和 tick0,我也尝试按照 plotly 网站上的示例进行操作,但它大多是具有相同图形类型的多个 y 轴.

                  I have tried playing with different attributes, such as 'mirror' and tick0, I also tried following the examples on plotly's site, but it's mostly multiple y-axis with the same graph type.

                  我能做些什么来解决这个问题?

                  What can I do to fix this?

                  import utils
                  import pandas as pd
                  import plotly.plotly as py
                  import plotly.graph_objs as go
                  import plotly
                  
                  
                  
                  
                  pd_data ['dt'] = ... dates
                  pd_data['price'] = ... prices
                  pd_data['car'] = ... cars
                  
                  price = go.Scatter(
                      x = pd_data['dt'],
                      y = pd_data['price'],
                      mode = 'lines',
                      name = 'Price',
                      xaxis = 'x',
                      yaxis='y1',     
                      marker = dict(
                          color = utils.prep_color_string('orange'),
                      ),
                      line = dict(
                          width = utils.line_width,
                      ),
                  )
                  
                  car = go.Bar(
                      x = pd_data['dt'],
                      y = pd_data['car'],
                      #mode = 'lines',
                      name = 'Cars',
                      xaxis = 'x',
                      yaxis='y2',
                      marker = dict(
                          color = utils.prep_color_string('light_green'),
                      ),
                      #line = dict(
                      #   width = utils.line_width,
                      #),
                  )
                  
                  data = [price, car]
                  
                  layout = dict(
                  
                      title = 'Price/Car',
                  
                      geo = dict(
                          showframe = True,
                          showcoastlines = True,
                          projection = dict(
                              type = 'Mercator'
                          )
                      ),
                  
                      yaxis=dict(
                          title = 'Price',
                          tickprefix = "$",
                          overlaying='y2',
                          anchor = 'x'            
                      ),
                  
                      yaxis2=dict(
                          title = 'Car',
                          dtick = 1,
                          #tickprefix = "",
                          side = 'right',
                          anchor = 'x',
                  
                      ),
                  
                  )
                  
                  fig = dict( data=data, layout=layout)
                  div = plotly.offline.plot( fig, validate=False, output_type = 'file',filename='graph.html' ,auto_open = False)
                  

                  推荐答案

                  我也一直在努力解决这个问题.完全相同的问题,但我使用的是 R.我想到的方法是对 yaxis 和 yaxis2 布局都使用 rangemode="tozero".

                  I have been struggling with this as well. Exact same problem, but I am using R. The way I figured around it was to use the rangemode="tozero" for both the yaxis and yaxis2 layouts.

                  我认为在你的情况下,它看起来像这样:

                  I think in your case, it would look like this:

                  layout = dict(
                  
                      title = 'Price/Car',
                  
                      geo = dict(
                          showframe = True,
                          showcoastlines = True,
                          projection = dict(
                              type = 'Mercator'
                          )
                      ),
                  
                      yaxis=dict(
                          title = 'Price',
                          tickprefix = "$",
                          overlaying='y2',
                          anchor = 'x',
                          rangemode='tozero'            
                      ),
                  
                      yaxis2=dict(
                          title = 'Car',
                          dtick = 1,
                          #tickprefix = "",
                          side = 'right',
                          anchor = 'x',
                          rangemode = 'tozero'
                  
                  
                      ),
                  
                  )
                  

                  让我知道这是否适合你.

                  Let me know if that works for you.

                  这篇关于Python Plotly - 为散点图和条形图对齐 Y 轴的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

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

                  相关文档推荐

                  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 数据框制作线图?)
                  <i id='HgLom'><tr id='HgLom'><dt id='HgLom'><q id='HgLom'><span id='HgLom'><b id='HgLom'><form id='HgLom'><ins id='HgLom'></ins><ul id='HgLom'></ul><sub id='HgLom'></sub></form><legend id='HgLom'></legend><bdo id='HgLom'><pre id='HgLom'><center id='HgLom'></center></pre></bdo></b><th id='HgLom'></th></span></q></dt></tr></i><div id='HgLom'><tfoot id='HgLom'></tfoot><dl id='HgLom'><fieldset id='HgLom'></fieldset></dl></div>
                    <bdo id='HgLom'></bdo><ul id='HgLom'></ul>
                  • <small id='HgLom'></small><noframes id='HgLom'>

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

                            <tfoot id='HgLom'></tfoot>

                              <tbody id='HgLom'></tbody>