<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 轴

        时间:2023-09-28
          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 轴的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  上一篇:在 plotly 弹出窗口中放置图表 下一篇:使用 Plotly 的 Slider 交互式绘图

                  相关文章

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