[英]Plotting multiple horizontal lines for each distribution in strip plot subplots Matplotlib
我试图将平均计算值绘制为通过我的数据集的每个绘制分布的中心的线。
我的代码看起来像这样:
for plot, var in zip(range(1, plot_num+1), var_list):
ax = fig.add_subplot(2, 2, plot)
# calculate averages
sns.stripplot(x=cluster_index_sample[cluster_type], y=cluster_index_sample[var],
jitter=jitter, linewidth=line_width, alpha=alpha, cmap=RS_colorwheel,
size=marker_size, ax=ax)
# create average lines
ax.axhline(y=cluster_index_sample['Average_'+(var)].iloc[0],
linewidth=3, xmin=0.2, xmax=0.5)
ax.set_ylabel(str(var), fontsize=y_lab)
ax.set_xlabel('')
ax.tick_params(axis='both', which='major', pad=10)
但是当我绘制这个时,每个cluster_type(x轴类别)只出现一次水平线。
我怎样才能得到它,以便每组编号的分类值得到各自的平均值?
由于您没有提供MCVE ,我无法运行您的代码。 不过,您可以尝试使用第二个for循环迭代所有变量以绘制水平平均线,如下所示。 您还必须修改每行的xmin
和xmax
。 我把它留给你。
for plot, var in zip(range(1, plot_num+1), var_list):
ax = fig.add_subplot(2, 2, plot)
sns.stripplot(x=cluster_index_sample[cluster_type], y=cluster_index_sample[var],
jitter=jitter, linewidth=line_width, alpha=alpha, cmap=RS_colorwheel,
size=marker_size, ax=ax)
for v in var_list: # <--- Added here
ax.axhline(y=cluster_index_sample['Average_'+(v)].iloc[0],
linewidth=3, xmin=0.2, xmax=0.5) # <--- Added here
ax.set_ylabel(str(var), fontsize=y_lab)
ax.set_xlabel('')
ax.tick_params(axis='both', which='major', pad=10)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.