带有数据点的x轴上的python / matplotlib / seaborn- boxplot [英] python/matplotlib/seaborn- boxplot on an x axis with data points
问题描述
我的数据集是这样的:一个有6个数字的python列表[23948.30、23946.20、23961.20、23971.70、23956.30、23987.30]
My data set is like this: a python list with 6 numbers [23948.30, 23946.20, 23961.20, 23971.70, 23956.30, 23987.30]
我希望它们成为x轴上方的水平框图,其中以[23855和24472]作为x轴的限制(无y轴)。
I want them to be be a horizontal box plot above an x axis with[23855 and 24472] as the limit of the x axis (with no y axis).
x轴还将在数据中包含点。
The x axis will also contain points in the data.
(因此箱形图和x轴具有
(so the box plot and x axis have the same scale)
我还希望方框图在图片中显示平均值。
I also want the box plot show the mean number in picture.
现在我可以仅获得水平框图。
(我也希望x轴显示整数而不是xx + 2.394e)
Now I can only get the horizontal box plot. (And I also want the x-axis show the whole number instead of xx+2.394e)
这是我的代码:
`
def box_plot(circ_list, wear_limit):
print circ_list
print wear_limit
fig1 = plt.figure()
plt.boxplot(circ_list, 0, 'rs', 0)
plt.show()
`
我正在尝试的季节性代码:
Seaborn code I am trying right now:
def box_plot(circ_list, wear_limit):
print circ_list
print wear_limit
#fig1 = plt.figure()
#plt.boxplot(circ_list, 0, 'rs', 0)
#plt.show()
fig2 = plt.figure()
sns.set(style="ticks")
x = circ_list
y = []
for i in range(0, len(circ_list)):
y.append(0)
f, (ax_box, ax_line) = plt.subplots(2, sharex=True,
gridspec_kw={"height_ratios": (.15, .85)})
sns.boxplot(x, ax=ax_box)
sns.pointplot(x, ax=ax_line, ay=y)
ax_box.set(yticks=[])
ax_line.set(yticks=[])
sns.despine(ax=ax_line)
sns.despine(ax=ax_box, left=True)
cur_axes = plt.gca()
cur_axes.axes.get_yaxis().set_visible(False)
sns.plt.show()
推荐答案
我也在另一篇文章中回答了这个问题,但是为了以防万一,我将其粘贴在这里。我还添加了一些我认为可能更接近于您要实现的目标。
I answered this question in the other post as well, but I will paste it here just in case. I also added something that I feel might be closer to what you are looking to achieve.
l = [23948.30, 23946.20, 23961.20, 23971.70, 23956.30, 23987.30]
def box_plot(circ_list):
fig, ax = plt.subplots()
plt.boxplot(circ_list, 0, 'rs', 0, showmeans=True)
plt.ylim((0.28, 1.5))
ax.set_yticks([])
labels = ["{}".format(int(i)) for i in ax.get_xticks()]
ax.set_xticklabels(labels)
ax.spines['right'].set_color('none')
ax.spines['top'].set_color('none')
ax.spines['left'].set_color('none')
ax.spines['bottom'].set_position('center')
ax.spines['bottom'].set_color('none')
ax.xaxis.set_ticks_position('bottom')
plt.show()
box_plot(l)
结果:
请让我知道它是否对应于什么你在找f或。
Do let me know if it correspond to what you were looking for.
这篇关于带有数据点的x轴上的python / matplotlib / seaborn- boxplot的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!