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

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

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

      1. Plotly:如何以 Root 样式绘制直方图,仅显示直方图的轮廓?

        时间:2023-09-28

        • <legend id='yYWpv'><style id='yYWpv'><dir id='yYWpv'><q id='yYWpv'></q></dir></style></legend>
              <tbody id='yYWpv'></tbody>

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

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

                  本文介绍了Plotly:如何以 Root 样式绘制直方图,仅显示直方图的轮廓?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  我想用这种风格制作直方图:

                  但是在 Python 中使用

                  完整代码

                  导入 plotly.graph_objects将熊猫导入为 pd将 numpy 导入为 np将 plotly.io 导入为 pio将 plotly.express 导入为 pxpio.templates.default = "plotly_white";# 随机数到 dfnp.random.seed(12)df = pd.DataFrame({'data': np.random.randn(500)})# 使用 numpy 生成直方图数据计数,索引 = np.histogram(df['data'], bins=25)# plotly, go.Scatter,线形设置为 'hvh'fig = go.Figure()fig.add_traces(go.Scatter(x=index, y = count,线=字典(宽度= 1,形状='hvh')))# y轴化妆品fig.update_yaxes(显示网格=假,蜱=内部",tickson=边界",滴答声=10,显示线=真,线宽=1,线条颜色='黑色',镜子=真,零线=假)# x轴化妆品fig.update_xaxes(显示网格=假,蜱=内部",tickson=边界",滴答声=10,显示线=真,线宽=1,线条颜色='黑色',镜子=真,零线=假)图.show()

                  为什么是 go.Scatter() 而不是 go.Histogram()?

                  使用 fig = go.Figure(data=[go.Histogram(x=x)]) 的方法最接近您想要的绘图是:

                  这非常接近,但您特别想排除每个条"的垂直线.而且我还没有找到使用 go.Histogram 设置排除或隐藏它们的方法.

                  go.Histogram()

                  的代码

                  导入 plotly.graph_objects将熊猫导入为 pd将 numpy 导入为 np将 plotly.io 导入为 pio将 plotly.express 导入为 pxpio.templates.default = "plotly_white";将 numpy 导入为 npx = np.random.randn(500)fig = go.Figure(data=[go.Histogram(x=x)])fig.update_traces(marker=dict(color='rgba(0,0,0,0)', line=dict(width=1, color='blue')))图.show()

                  I want to make a histogram with this style:

                  But using plotly in Python. I.e. I want to merge the bars and plot only the contour. I am using this code:

                  import plotly.graph_objects as go
                  
                  import numpy as np
                  
                  x = np.random.randn(500)
                  fig = go.Figure(data=[go.Histogram(x=x)])
                  fig.show()
                  

                  I have been looking for examples on how to do this but could not find any.

                  解决方案

                  Your best option is to handle the histogram with numpy like count, index = np.histogram(df['data'], bins=25) , and then use go.Scatter() and set the linetype to horizontal, vertical, horizontal with line=dict(width = 1, shape='hvh'). Take a look at the very last section why go.Histogram() will not be your best option. With a few other specifications for the layout of go.Scatter(), the snippet below will produce the following plot:

                  Complete code

                  import plotly.graph_objects as go
                  import pandas as pd
                  import numpy as np
                  import plotly.io as pio
                  import plotly.express as px
                  
                  pio.templates.default = "plotly_white"
                  
                  # random numbers to a df
                  np.random.seed(12)
                  df = pd.DataFrame({'data': np.random.randn(500)})
                  
                  # produce histogram data wiht numpy
                  count, index = np.histogram(df['data'], bins=25)
                  
                  # plotly, go.Scatter with line shape set to 'hvh'
                  fig = go.Figure()
                  fig.add_traces(go.Scatter(x=index, y = count,
                                            line=dict(width = 1, shape='hvh')))
                  
                  # y-axis cosmetics
                  fig.update_yaxes(
                      showgrid=False,
                      ticks="inside",
                      tickson="boundaries",
                      ticklen=10,
                      showline=True,
                      linewidth=1,
                      linecolor='black',
                      mirror=True,
                      zeroline=False)
                  
                  # x-axis cosmetics
                  fig.update_xaxes(
                      showgrid=False,
                      ticks="inside",
                      tickson="boundaries",
                      ticklen=10,
                      showline=True,
                      linewidth=1,
                      linecolor='black',
                      mirror=True,
                      zeroline=False)
                  
                  fig.show()
                  

                  Why go.Scatter() and not go.Histogram()?

                  The closest you'll get to your desired plot using your approach with fig = go.Figure(data=[go.Histogram(x=x)]) is this:

                  And that's pretty close, but you specifically wanted to exclude the vertical lines for each "bar". And I have yet not found a way to exclude or hide them with the go.Histogram setup.

                  Code for go.Histogram()

                  import plotly.graph_objects as go
                  import pandas as pd
                  import numpy as np
                  import plotly.io as pio
                  import plotly.express as px
                  
                  pio.templates.default = "plotly_white"
                  
                  import numpy as np
                  
                  x = np.random.randn(500)
                  fig = go.Figure(data=[go.Histogram(x=x)])
                  fig.update_traces(marker=dict(color='rgba(0,0,0,0)', line=dict(width=1, color='blue')))
                  fig.show()
                  

                  这篇关于Plotly:如何以 Root 样式绘制直方图,仅显示直方图的轮廓?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  上一篇:手动更改 plotly scatterpolar 标签 下一篇:颜色条最小值和最大值

                  相关文章

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

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

                • <tfoot id='GqaRU'></tfoot>

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

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