mma*_*ion 5 python plotly plotly-dash plotly-python plotly-express
如果你\xe2\x80\x99和我一样,你喜欢Plotly Express,但是当你遇到Express返回的数字可以\xe2\x80\x99t利用\xe2\x80\x98make_subplots()\xe2\x80的问题时感到沮丧\x99 因为 make_subplots 接受的是痕迹而不是数字。在这篇文章中,我\xe2\x80\x99d想分享我自己的解决方案,关于如何仅使用Plotly Express(和plotly.subplots)创建包含两种不同类型的图形(如下所示)的子图
\n\nmma*_*ion 12
import plotly.express as px\nimport plotly.subplots as sp\nimport dash_core_components as dcc\n\n# Create figures in Express\nfigure1 = px.line(my_df)\nfigure2 = px.bar(my_df)\n\n# For as many traces that exist per Express figure, get the traces from each plot and store them in an array.\n# This is essentially breaking down the Express fig into it's traces\nfigure1_traces = []\nfigure2_traces = []\nfor trace in range(len(figure1["data"])):\n figure1_traces.append(figure1["data"][trace])\nfor trace in range(len(figure2["data"])):\n figure2_traces.append(figure2["data"][trace])\n\n#Create a 1x2 subplot\nthis_figure = sp.make_subplots(rows=1, cols=2) \n\n# Get the Express fig broken down as traces and add the traces to the proper plot within in the subplot\nfor traces in figure1_traces:\n this_figure.append_trace(traces, row=1, col=1)\nfor traces in figure2_traces:\n this_figure.append_trace(traces, row=1, col=2)\n\n#the subplot as shown in the above image\nfinal_graph = dcc.Graph(figure=this_figure)\nRun Code Online (Sandbox Code Playgroud)\n由于我正在处理的项目数据的敏感性,我无法\xe2\x80\x99t 共享我的程序\xe2\x80\x99s 输出的实际图像,但它看起来与上图。据我\xe2\x80\x99测试,这应该适用于任何 Express 人物。
\n我希望这对某些人有用。大家策划愉快!
\n| 归档时间: |
|
| 查看次数: |
6418 次 |
| 最近记录: |