如何交换箱线图中的 x 标签?
How to swap the x-labels in a boxplot?
我有几个箱线图,x 轴上有问题标识符(例如 A1、A2、A3)。我喜欢用自定义文本替换标识符。
这没有任何作用
plt.xticks([1, 2, 3, 4, 5, 6, 7, 8,9,10],['b1', 'b2', 'b3', 'b4', 'b5', 'A6', 'A7', 'A8', 'A9','A10'])
这没有任何作用
plt.xticks(['A1', 'A2', 'A3', 'A4', 'A5', 'A6', 'A7', 'A8', 'A9','A10'],['b1', 'b2', 'b3', 'b4', 'b5', 'A6', 'A7', 'A8', 'A9','A10'])
这没有任何作用
plt.xticks([],[])
我的代码
whiskerprops = dict(linestyle='-', linewidth=4.0, color='cyan')
boxprops = dict(linewidth=4.0, color='black')
capprops = dict(linewidth=4.0, color='red')
medianprops = dict(linewidth=4.0, color='black')
plt.text(2,7,"test")
plt.xticks([])
plt.tick_params(
axis='x',
which='both',
bottom=False,
labelbottom='off' #works to hide the labels
)
flierprops = dict(marker='o', markersize=12, linestyle='none', markeredgecolor='green', markerfacecolor='red')
boxplot = alert_df.boxplot(column=['A1', 'A2', 'A3', 'A4', 'A5', 'A6', 'A7', 'A8', 'A9','A10'], # these are the question IDs I like to replace
figsize=(15,5),
fontsize=15,
patch_artist=True,
notch=True,
whiskerprops=whiskerprops,
boxprops=boxprops,
capprops = capprops,
medianprops=medianprops,
flierprops = flierprops,
rot=35,
)
我喜欢的是替代品:
- A1 -> "This is question 1"
- A2 -> "This is question 2"
- 等等
ax.set_xticklabels
就是您要找的
fig, ax = plt.subplots(1,1, figsize=(15,5))
df.boxplot(ax=ax)
ax.set_xticklabels([f'Q{i}' for i in range(1,11)]);
我有几个箱线图,x 轴上有问题标识符(例如 A1、A2、A3)。我喜欢用自定义文本替换标识符。
这没有任何作用
plt.xticks([1, 2, 3, 4, 5, 6, 7, 8,9,10],['b1', 'b2', 'b3', 'b4', 'b5', 'A6', 'A7', 'A8', 'A9','A10'])
这没有任何作用
plt.xticks(['A1', 'A2', 'A3', 'A4', 'A5', 'A6', 'A7', 'A8', 'A9','A10'],['b1', 'b2', 'b3', 'b4', 'b5', 'A6', 'A7', 'A8', 'A9','A10'])
这没有任何作用
plt.xticks([],[])
我的代码
whiskerprops = dict(linestyle='-', linewidth=4.0, color='cyan')
boxprops = dict(linewidth=4.0, color='black')
capprops = dict(linewidth=4.0, color='red')
medianprops = dict(linewidth=4.0, color='black')
plt.text(2,7,"test")
plt.xticks([])
plt.tick_params(
axis='x',
which='both',
bottom=False,
labelbottom='off' #works to hide the labels
)
flierprops = dict(marker='o', markersize=12, linestyle='none', markeredgecolor='green', markerfacecolor='red')
boxplot = alert_df.boxplot(column=['A1', 'A2', 'A3', 'A4', 'A5', 'A6', 'A7', 'A8', 'A9','A10'], # these are the question IDs I like to replace
figsize=(15,5),
fontsize=15,
patch_artist=True,
notch=True,
whiskerprops=whiskerprops,
boxprops=boxprops,
capprops = capprops,
medianprops=medianprops,
flierprops = flierprops,
rot=35,
)
我喜欢的是替代品:
- A1 -> "This is question 1"
- A2 -> "This is question 2"
- 等等
ax.set_xticklabels
就是您要找的
fig, ax = plt.subplots(1,1, figsize=(15,5))
df.boxplot(ax=ax)
ax.set_xticklabels([f'Q{i}' for i in range(1,11)]);