python - 如何使用破折号在子图中设置轴标签
问题描述
我用 plotly.subplots 模块中的 make_subplots() 创建了一个图形
如何为每个子图设置 x 和 y 轴标签?
解决方案
从情节文档:
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)
fig.show()
推荐阅读
- rhel - Java 代码在 AIX 3.5 中正常,在 RHEL 7.5 中失败:它会生成损坏的 DOC、DOCX、XLS、XLSX 文件,但会生成良好的 HTML 文件
- sorting - 向排序列表添加少量元素时如何更快地排序?
- python - 为什么测试没有检测到 test.py 的语法错误?并帮我修复一个错误
- php - 获取具有完整路径的类别列表
- arrays - 如何将第二个向量合并到第一个向量,但从预定义的不同位置,而不是从延续?
- ios - 即使我重新安装应用程序,Firebase 也会让我保持登录状态
- node.js - 在 csv 文件中写入数据时遇到问题
- hadoop - Pyspark:使用 configParser 读取 HDFS 上的属性文件
- reactjs - 开玩笑模拟不在文本框上显示文本
- cassandra - 数据中心宕机后的 Cassandra 修复