Sul*_*rif 2 python python-3.x plotly plotly-python
我创建了一个子图,老实说,在情节文档中并不清楚如何使这些标题更大。
\nhttps://plotly.com/python-api-reference/ generated/plotly.subplots.make_subplots.html
\n这是供参考的文档,他们谈论设置 x_axis 标题和 y_axis 标题。我做到了,但我似乎找不到修改它的方法。
\n\nfig = make_subplots(\n rows=6, cols=4,\n subplot_titles=subplot_titles,\n y_title=\'Distance (\xc3\x85)\',\n x_title=\'Resid ID\'\n)\n\npositions = [\n [1, 1], [1, 2], [1, 3], [1, 4],\n [2, 1], [2, 2], [2, 3], [2, 4],\n [3, 1], [3, 2], [3, 3], [3, 4],\n [4, 1], [4, 2], [4, 3], [4, 4],\n [5, 1], [5, 2], [5, 3], [5, 4],\n [6, 1], [6, 2], [6, 3], [6, 4],\n ]\n\n\nfor i in range(0, len(segids)):\n \n fig.add_trace(\n go.Scattergl(\n x=resid_titles,\n y=list(copy[segids[i]].values()),\n line=dict(color=colors[0]),\n \n ),\n \n \n row=int(positions[i][0]), \n col=int(positions[i][1])\n )\n \n\n# Set title\nfig.update_layout(title_text="Average O5-O3 Distance Per Resid Per Chain")\n\nfig.update_layout(\n title_font_family="Arial",\n title_font_color="Black",\n title_font=dict(size=44, family=\'Courier\'),\n\n)\n\n# Remove the Legend\nfig.update_layout(showlegend=False)\n\nfig.update_xaxes(\n ticks="outside",\n tickwidth=2,\n tickcolor=\'black\',\n tickfont=dict(family=\'Arial\', color=\'black\', size=22),\n title_font=dict(size=44, family=\'Arial\'),\n range=[1, 9],\n)\n\nfig.update_yaxes(\n ticks="outside", \n tickwidth=2,\n tickcolor=\'black\', \n tickfont=dict(family=\'Arial\', color=\'black\', size=22),\n title_font=dict(size=44, family=\'Arial\'),\n range=[2, 5]\n)\nRun Code Online (Sandbox Code Playgroud)\n我尝试过使用他们的 update_xaxes 函数,但不起作用。
\n“Resid ID”和“Distance”轴标题 -> 我希望它们更大,也许改变颜色。有没有一种方法可以实现我所缺少的?
\n这是一张图片供参考
\n\n您可以使用:
fig.for_each_xaxis(lambda axis: axis.title.update(font=dict(color = 'blue', size=20)))
Run Code Online (Sandbox Code Playgroud)
基于plotly 文档中的子图示例,以下代码片段...
fig.for_each_xaxis(lambda axis: axis.title.update(font=dict(size=24)))
fig.for_each_yaxis(lambda axis: axis.title.update(font=dict(size=24)))
Run Code Online (Sandbox Code Playgroud)
...将改变这个:
...进入这个:
from plotly.subplots import make_subplots
import plotly.graph_objects as go
# Initialize figure with subplots
fig = make_subplots(
rows=2, cols=2, subplot_titles=("Plot 1", "Plot 2", "Plot 3", "Plot 4")
)
# Add traces
fig.add_trace(go.Scatter(x=[1, 2, 3], y=[4, 5, 6]), row=1, col=1)
fig.add_trace(go.Scatter(x=[20, 30, 40], y=[50, 60, 70]), row=1, col=2)
fig.add_trace(go.Scatter(x=[300, 400, 500], y=[600, 700, 800]), row=2, col=1)
fig.add_trace(go.Scatter(x=[4000, 5000, 6000], y=[7000, 8000, 9000]), row=2, col=2)
# Update xaxis properties
fig.update_xaxes(title_text="xaxis 1 title", row=1, col=1)
fig.update_xaxes(title_text="xaxis 2 title", range=[10, 50], row=1, col=2)
fig.update_xaxes(title_text="xaxis 3 title", showgrid=False, row=2, col=1)
fig.update_xaxes(title_text="xaxis 4 title", type="log", row=2, col=2)
# Update yaxis properties
fig.update_yaxes(title_text="yaxis 1 title", row=1, col=1)
fig.update_yaxes(title_text="yaxis 2 title", range=[40, 80], row=1, col=2)
fig.update_yaxes(title_text="yaxis 3 title", showgrid=False, row=2, col=1)
fig.update_yaxes(title_text="yaxis 4 title", row=2, col=2)
# Update title and height
fig.update_layout(title_text="Customizing Subplot Axes", height=700)
# change subplot axes font size
fig.for_each_xaxis(lambda axis: axis.title.update(font=dict(color = 'blue', size=20)))
fig.for_each_yaxis(lambda axis: axis.title.update(font=dict(color = 'blue', size=20)))
fig.show()
Run Code Online (Sandbox Code Playgroud)