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:如何为每个不同的子图应用不同的标题?
基础教程推荐
- 用 Python 编写 Fortran 无格式文件 2022-01-01
- Discord.py 缺少必需的参数 2022-01-01
- 将 x 轴刻度更改为自定义字符串 2022-01-01
- numpy float:比算术运算中内置的慢 10 倍? 2022-01-01
- 与常规 dict 相比,Python manager.dict() 非常慢 2022-01-01
- 使用生成器和迭代器时 Python 多循环失败 2022-01-01
- 尝试制作WhatsApp机器人 2022-01-01
- 由Python将MP3转换为MIDI(类型错误:无法加载插件:mtg-Melodia:Melodia) 2022-01-01
- 在 Celery 工作人员中捕获 Heroku SIGTERM 以优雅地关 2022-01-01
- pyserial - 可以从线程 a 写入串行端口,是否阻塞从线程 b 读取? 2022-01-01
