python - 如何在 Plotly 中制作多面图有自己的 YAxes 刻度标签?
问题描述
当我使用 Plotly express 绘制具有不同范围的不同参数时 - 在下面的示例中,BloodPressureHigh、Height(cm)、Weight(kg) 和 BloodPressureLow - 使用该facet_col
参数,我无法获得结果图来显示唯一的 YTicks对于每个多面图。对象是否有一种简单的方法可以fig
在生成的多面图中显示每组 YTicks?否则,正如您在生成的图像中看到的那样,不清楚每个箱线图是否在其自己独特的 Y 轴上。
import plotly.express as px
import pandas as pd
temp = [
{"Clinic": "A", "Subject": "Bill", "Height(cm)": 182, "Weight(kg)": 101, "BloodPressureHigh": 128, "BloodPressureLow": 90},
{"Clinic": "A", "Subject": "Susie", "Height(cm)": 142, "Weight(kg)": 67, "BloodPressureHigh": 120, "BloodPressureLow": 70},
{"Clinic": "B", "Subject": "John", "Height(cm)": 202, "Weight(kg)": 89, "BloodPressureHigh": 118, "BloodPressureLow": 85},
{"Clinic": "B", "Subject": "Stacy", "Height(cm)": 156, "Weight(kg)": 78, "BloodPressureHigh": 114, "BloodPressureLow": 76},
{"Clinic": "B", "Subject": "Lisa", "Height(cm)": 164, "Weight(kg)": 59, "BloodPressureHigh": 112, "BloodPressureLow": 74}
]
df = pd.DataFrame(temp)
# Melt the dataframe so I can use plotly express to plot distributions of all variables
df_melted = df.melt(id_vars=["Clinic", "Subject"])
# Plot distributions, with different parameters in different columns
fig = px.box(df_melted, x="Clinic", y="value",
facet_col="variable", boxmode="overlay"
)
# Update the YAxes so that the faceted column plots no longer share common YLimits
fig.update_yaxes(matches=None)
# Last step needed: Add tick labels to each yaxis so that the difference in YLimits is clear?
解决方案
推荐阅读
- java - 为什么我的服务类的 createPerson() 返回 null?
- java - 清单文件中未生成主类
- python - 如何将单层神经网络乘以实数?
- python - Python 请求会话忽略验证设置
- reactjs - 通过加密反应原生应用程序构建错误
- tls1.2 - 大使可以强制执行自己的密码顺序偏好吗?
- c++ - 为什么使用 ++i 与 i++ 时循环运行的次数没有差异?
- android - 捕获图像输出文件android 10
- java - Spring boot 无法评估表达式方法抛出 'org.hibernate.LazyInitializationException' 异常。使用 getter,ManyToMany 关系
- html - 具有动态内容的打字机效果