如何将标签添加到箱线图(pylab)

2024-09-26 22:10:47 发布

您现在位置:Python中文网/ 问答频道 /正文

这是一个非常基本的问题,我敢肯定,但我似乎找不到正确的代码。 这是我正在创建的boxplot的代码。我想给斧头贴上标签并有个标题。

from pylab import *
import numpy
raw_data = list(numpy.genfromtxt(filename, delimiter=','))
print raw_data
figure()
boxplot(raw_data,1)
savefig('testfigure.pdf')

我试过pylab.xlabel('x')plt.xlable('x')但它们不起作用。。。?它们不适用于boxplots吗?还是我刚刚误解了那些行的工作原理?


Tags: 代码fromimportnumpy标题datarawfilename
1条回答
网友
1楼 · 发布于 2024-09-26 22:10:47

试试这个:

import matplotlib.pyplot as plt
from pylab import *

# fake up some data
spread= rand(50) * 100
center = ones(25) * 50
flier_high = rand(10) * 100 + 100
flier_low = rand(10) * -100
data =concatenate((spread, center, flier_high, flier_low), 0)

# figure related code
fig = plt.figure()
fig.suptitle('bold figure suptitle', fontsize=14, fontweight='bold')

ax = fig.add_subplot(111)
ax.boxplot(data)

ax.set_title('axes title')
ax.set_xlabel('xlabel')
ax.set_ylabel('ylabel')

plt.show()

编辑:图片

enter image description here

相关问题 更多 >

    热门问题