Plotly: How to apply different titles for each different subplots?(Plotly:如何为每个不同的子图应用不同的标题?)
问题描述
鉴于我有来自
代码:
from plotly.subplots import make_subplots导入 plotly.graph_objects# plotly fig 设置fig = make_subplots(rows=1,列= 2,subplot_titles=('子图标题1', '子图标题2'))# 痕迹fig.add_trace(go.Scatter(x=[1, 2, 3], y=[4, 5, 6]),行=1,列=1)fig.add_trace(go.Scatter(x=[20, 30, 40], y=[50, 60, 70]),行=1,列=2)# 编辑轴标签fig['layout']['xaxis']['title']='标注x轴1'fig['layout']['xaxis2']['title']='标注x轴2'fig['layout']['yaxis']['title']='标注y轴1'fig['layout']['yaxis2']['title']='标注y轴2'# 绘制它图.show()
Given that i have the below code from this link:
from plotly.subplots import make_subplots
import plotly.graph_objects as go
fig = make_subplots(rows=1, cols=2)
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.update_layout(height=600, width=800, title_text="Subplots")
fig.show()
The problem in this code is, the xaxis
and yaxis
does not have any label. Beside this, the current code applies only one title to all the plots, however I want to apply different titles to each scatter plot.
How can i do that?
The problem in this code is, the xaxis and yaxis does not have any label.
You can edit any axis by subsetting the structure of your figure:
fig['layout']['xaxis']['title']='Label x-axis 1'
Beside this, the current code applies only one title to all the plots
Depending on your plotly version as mentioned by user shaik moeed, you can include subplot_titles
in your figure definition:
fig = make_subplots(rows=1, cols=2, subplot_titles=('Subplot title1', 'Subplot title2'))
Plot:
Code:
from plotly.subplots import make_subplots
import plotly.graph_objects as go
# plotly fig setup
fig = make_subplots(rows=1,
cols=2,
subplot_titles=('Subplot title1', 'Subplot title2'))
# 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
)
# edit axis labels
fig['layout']['xaxis']['title']='Label x-axis 1'
fig['layout']['xaxis2']['title']='Label x-axis 2'
fig['layout']['yaxis']['title']='Label y-axis 1'
fig['layout']['yaxis2']['title']='Label y-axis 2'
# plot it
fig.show()
这篇关于Plotly:如何为每个不同的子图应用不同的标题?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:Plotly:如何为每个不同的子图应用不同的标题?
基础教程推荐
- 线程时出现 msgbox 错误,GUI 块 2022-01-01
- Python kivy 入口点 inflateRest2 无法定位 libpng16-16.dll 2022-01-01
- Dask.array.套用_沿_轴:由于额外的元素([1]),使用dask.array的每一行作为另一个函数的输入失败 2022-01-01
- 用于分类数据的跳跃记号标签 2022-01-01
- 筛选NumPy数组 2022-01-01
- 何时使用 os.name、sys.platform 或 platform.system? 2022-01-01
- 如何让 python 脚本监听来自另一个脚本的输入 2022-01-01
- 如何在海运重新绘制中自定义标题和y标签 2022-01-01
- 在 Python 中,如果我在一个“with"中返回.块,文件还会关闭吗? 2022-01-01
- 使用PyInstaller后在Windows中打开可执行文件时出错 2022-01-01