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

  • <small id='HtpOL'></small><noframes id='HtpOL'>

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

    <tfoot id='HtpOL'></tfoot>

      1. PLOTLY:如何使用GRAPH_OBJECTS创建日出子图?

        Plotly: How to create sunburst subplot using graph_objects?(PLOTLY:如何使用GRAPH_OBJECTS创建日出子图?)

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

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

            1. <small id='nREiX'></small><noframes id='nREiX'>

                    <tbody id='nREiX'></tbody>
                  本文介绍了PLOTLY:如何使用GRAPH_OBJECTS创建日出子图?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  我的数据帧如下所示:

                      user    age   gender
                  0    23     12     male
                  1    24     13     male
                  2    25     15     female
                  3    26     20     male
                  4    27     21     male
                  

                  和使用

                  px.sunburst(df, path=["gender", "age"])
                  

                  给我正确的日出图,其中性别在饼图的中间部分,并且每个性别都有关联的年龄。

                  我希望使用GRAPH_OBJECTS而不是Plot Express执行此操作,因为我希望两个Sunburst图并排出现。

                  从上面的df中,我可以如何在graph_Objects中使用它。我不知道要为标签、父项、ID等添加什么值.

                  fig = go.Figure()
                  
                  fig.add_trace(
                      go.Sunburst(
                          lables = df.age,
                          parents = df.gender,
                          domain=dict(column=0)
                      )
                  )
                  
                  fig.show()
                  

                  我已经阅读了文档,但是我不明白它是如何工作的。如果有人知道,请告诉我如何通过上面的df使用graph_object创建日出图。

                  推荐答案

                  答案:

                  只需使用px构建一个图形,然后从那里窃取您的所有图形元素,并在graph_Objects图形中使用它,即可获得您需要的内容!


                  详情:

                  如果px确实提供了所需的日出图表,如下所示:

                  绘图1:

                  代码1:

                  # imports
                  import pandas as pd
                  import plotly.graph_objects as go
                  import plotly.express as px
                  
                  # data
                  df = pd.DataFrame({'user':  [23, 24, 25,    26, 27],
                                     'age':   [12, 13,15, 20, 21],
                                     'gender':    ['male','male', 'female','male', 'male'] })
                  
                  # plotly express figure
                  fig = px.sunburst(df, path=["gender", "age"])
                  fig.show()
                  
                  那么,据我所知,您必须重新构造数据才能使用graph_objects。当前,您的数据格式为

                  graph_objects需要label = ['12', '13', '15', '20', '21', 'female', 'male']。那现在怎么办?经历为每个元素找到正确的数据结构的痛苦吗?否,只需使用px生成一个图形,然后从其中窃取所有图形元素并在graph_objects图形中使用它:

                  代码2:

                  # imports
                  import pandas as pd
                  import plotly.graph_objects as go
                  import plotly.express as px
                  
                  # data
                  df = pd.DataFrame({'user':  [23, 24, 25,    26, 27],
                                     'age':   [12, 13,15, 20, 21],
                                     'gender':    ['male','male', 'female','male', 'male'] })
                  
                  # plotly express figure
                  fig = px.sunburst(df, path=["gender", "age"])
                  
                  # plotly graph_objects figure
                  fig2 =go.Figure(go.Sunburst(
                                  labels=fig['data'][0]['labels'].tolist(),
                                  parents=fig['data'][0]['parents'].tolist(),
                                              )
                                  )
                  fig2.show()
                  

                  绘图2:

                  现在,如果您想在同一张图中显示数据集的更多功能,只需将ids=fig['data'][0]['ids'].tolist()添加到混合中:

                  绘图3:

                  完整代码:

                  # imports
                  import pandas as pd
                  import plotly.graph_objects as go
                  import plotly.express as px
                  
                  # data
                  df = pd.DataFrame({'user':  [23, 24, 25,    26, 27],
                                     'age':   [12, 13,15, 20, 21],
                                     'gender':    ['male','male', 'female','male', 'male'] })
                  
                  # plotly express figure
                  fig = px.sunburst(df, path=["gender", "age"])
                  
                  # plotly graph_objects figure
                  fig2 =go.Figure(go.Sunburst(
                      labels=fig['data'][0]['labels'].tolist(),
                      parents=fig['data'][0]['parents'].tolist(),
                      values=fig['data'][0]['values'].tolist(),
                      ids=fig['data'][0]['ids'].tolist(),
                      domain={'x': [0.0, 1.0], 'y': [0.0, 1.0]}
                  ))
                  
                  fig2.show()
                  

                  这篇关于PLOTLY:如何使用GRAPH_OBJECTS创建日出子图?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

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

                  相关文档推荐

                  GUI Freezes while downloading PyQt5 and Pytube(GUI在下载PyQt5和Pytube时冻结)
                  How to solve memory issues while multiprocessing using Pool.map()?(如何解决使用Pool.map()进行多处理时的内存问题?)
                  Python - How to use FastAPI and uvicorn.run without blocking the thread?(Python-如何使用FastAPI和uvicorn.run而不阻塞线程?)
                  How to increment a shared counter from multiple processes?(如何从多个进程递增共享计数器?)
                  Using pika, how to connect to rabbitmq running in docker, started with docker-compose with external network?(使用pika,如何连接运行在docker中的rabbitmq,从docker开始-与外部网络连接?)
                  How to use .rolling() on each row of a Pandas dataframe?(如何对 pandas 数据帧的每一行使用.roll()?)

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

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

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

                          <tbody id='fSVBu'></tbody>

                            <tfoot id='fSVBu'></tfoot>