如何在子图中显示不同的 yaxis 值?
How do I show different yaxis value in a subplot?
我想在第一行显示不同的范围,在第二行显示不同的范围?
例如第一行最多可以显示 50,第二行最多可以显示 100?
from plotly.subplots import make_subplots
import plotly.graph_objects as go
import plotly.express as px
import numpy as np
import pandas as pd
# set seed
np.random.seed(41)
#create three different normally distributed datasets
score_array_A = np.random.normal(size = 100, loc = 15, scale=5)
score_array_B = np.random.normal(size = 200, loc = 50, scale=10)
score_array_C = np.random.normal(size = 300, loc = 70, scale=15)
#turn normal arrays into dataframes
#score_data['T(s)']
score_df_A = pd.DataFrame({'T(s)':score_array_A,'D':'2'})
score_df_B = pd.DataFrame({'T(s)':score_array_B,'D':'3'})
score_df_C = pd.DataFrame({'T(s)':score_array_C,'D':'4'})
#concat dataframes together
score_data = pd.concat([score_df_A,score_df_B,score_df_C])
score_data = score_data.assign(Req = np.where(score_data['T(s)']%5 > 1, "1", "5"))
#to plot subplots
px.box(data_frame = score_data
,y = 'T(s)'
,facet_col = 'D'
, facet_row = 'Req'
,facet_col_wrap = 0,
template='simple_white',
width=600,
height=300
)
使用 Plotly Express 创建图形后,更新每个 yaxis,使其不配置为与主 yaxis 匹配。还更新了 showticklabels
import plotly.express as px
import numpy as np
import pandas as pd
# set seed
np.random.seed(41)
# create three different normally distributed datasets
score_array_A = np.random.normal(size=100, loc=15, scale=5)
score_array_B = np.random.normal(size=200, loc=50, scale=10)
score_array_C = np.random.normal(size=300, loc=70, scale=15)
# turn normal arrays into dataframes
# score_data['T(s)']
score_df_A = pd.DataFrame({"T(s)": score_array_A, "D": "2"})
score_df_B = pd.DataFrame({"T(s)": score_array_B, "D": "3"})
score_df_C = pd.DataFrame({"T(s)": score_array_C, "D": "4"})
# concat dataframes together
score_data = pd.concat([score_df_A, score_df_B, score_df_C])
score_data = score_data.assign(Req=np.where(score_data["T(s)"] % 5 > 1, "1", "5"))
# to plot subplots
fig = px.box(
data_frame=score_data,
y="T(s)",
facet_col="D",
facet_row="Req",
facet_col_wrap=0,
template="simple_white",
width=600,
height=300,
)
fig.update_layout(
{
yax: {"matches": None, "showticklabels": True}
for yax in fig.to_dict()["layout"].keys()
if "yaxis" in yax
}
)
我想在第一行显示不同的范围,在第二行显示不同的范围? 例如第一行最多可以显示 50,第二行最多可以显示 100?
from plotly.subplots import make_subplots
import plotly.graph_objects as go
import plotly.express as px
import numpy as np
import pandas as pd
# set seed
np.random.seed(41)
#create three different normally distributed datasets
score_array_A = np.random.normal(size = 100, loc = 15, scale=5)
score_array_B = np.random.normal(size = 200, loc = 50, scale=10)
score_array_C = np.random.normal(size = 300, loc = 70, scale=15)
#turn normal arrays into dataframes
#score_data['T(s)']
score_df_A = pd.DataFrame({'T(s)':score_array_A,'D':'2'})
score_df_B = pd.DataFrame({'T(s)':score_array_B,'D':'3'})
score_df_C = pd.DataFrame({'T(s)':score_array_C,'D':'4'})
#concat dataframes together
score_data = pd.concat([score_df_A,score_df_B,score_df_C])
score_data = score_data.assign(Req = np.where(score_data['T(s)']%5 > 1, "1", "5"))
#to plot subplots
px.box(data_frame = score_data
,y = 'T(s)'
,facet_col = 'D'
, facet_row = 'Req'
,facet_col_wrap = 0,
template='simple_white',
width=600,
height=300
)
使用 Plotly Express 创建图形后,更新每个 yaxis,使其不配置为与主 yaxis 匹配。还更新了 showticklabels
import plotly.express as px
import numpy as np
import pandas as pd
# set seed
np.random.seed(41)
# create three different normally distributed datasets
score_array_A = np.random.normal(size=100, loc=15, scale=5)
score_array_B = np.random.normal(size=200, loc=50, scale=10)
score_array_C = np.random.normal(size=300, loc=70, scale=15)
# turn normal arrays into dataframes
# score_data['T(s)']
score_df_A = pd.DataFrame({"T(s)": score_array_A, "D": "2"})
score_df_B = pd.DataFrame({"T(s)": score_array_B, "D": "3"})
score_df_C = pd.DataFrame({"T(s)": score_array_C, "D": "4"})
# concat dataframes together
score_data = pd.concat([score_df_A, score_df_B, score_df_C])
score_data = score_data.assign(Req=np.where(score_data["T(s)"] % 5 > 1, "1", "5"))
# to plot subplots
fig = px.box(
data_frame=score_data,
y="T(s)",
facet_col="D",
facet_row="Req",
facet_col_wrap=0,
template="simple_white",
width=600,
height=300,
)
fig.update_layout(
{
yax: {"matches": None, "showticklabels": True}
for yax in fig.to_dict()["layout"].keys()
if "yaxis" in yax
}
)