是否可以在箱线图的左侧和右侧设置刻度线的方向?当我x_or_y_axis.set_tick_params(direction='whatever')
更改框两侧的刻度线的方向时:
_______________ _______________
-| |- |- -|
| | |- -|
-| |- |- -|
| | |- -|
-|_______________|- or |_______________|
但我需要:
_______________ _______________
|- |- -| -|
| | | |
|- |- -| -|
| | | |
|-______________|- or -|_____________-|
一种选择是使用创建双轴ax.twinx()
,然后可以分别控制yticks
两个轴上的。
然后,您可能还希望在两个轴之间共享y轴,以使两个轴之间的轴限制和刻度线相同。我们可以在这里使用答案。
这是一个最小的示例,是从boxplot
演示中修改而来的:
import matplotlib.pyplot as plt
import numpy as np
# fake up some data
spread = np.random.rand(50) * 100
center = np.ones(25) * 50
flier_high = np.random.rand(10) * 100 + 100
flier_low = np.random.rand(10) * -100
data = np.concatenate((spread, center, flier_high, flier_low), 0)
# Make the figure and axes
fig,ax = plt.subplots(1)
# Add you twin axes
ax2 = ax.twinx()
# Set the ticks to the outside on the right only
ax2.tick_params(axis='y',direction='out')
# Make sure the ticks and axes limits are shared between the left and right
ax.get_shared_y_axes().join(ax,ax2)
# basic boxplot
ax.boxplot(data)
plt.show()
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句