本文介绍了如何在箱线图上添加标签(pylab)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我敢肯定这是一个非常基本的问题,但是我似乎找不到正确的代码.有我要创建的箱线图的代码.我想标记轴并有一个标题.

This is a pretty basic question I'm sure but I cannot seem to find the right code.There is my code for the boxplot I am creating. I would like to label the axes and have a title.

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'),但是这些方法不起作用...?他们不是为箱线图工作吗,还是我只是对那些线的工作有误?

I have tried pylab.xlabel('x') and plt.xlable('x') but those do not work...? Do they not work for boxplots or have I just got it wrong about those lines working?

推荐答案

尝试一下:

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()

图片

这篇关于如何在箱线图上添加标签(pylab)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-15 22:55