我用下面的代码绘制了一个简单的boxplots,但是从结果中可以看出,有些单词是从图像中剪切出来的。我怎么解决这个问题?在
def generate_data_boxplots(data, ticks, x_axis_label, y_axis_label, file_path):
"""
Plot multiple data boxplots in parallel
:param data : a set of data to be plotted
:param x_axis_label : the x axis label of the data
:param y_axis_label : the y axis label of the data
:param file_path : the path where the output will be save
"""
plt.figure()
bp = plt.boxplot(data, sym='r+')
plt.xticks(numpy.arange(1, len(ticks)+1), ticks, rotation=15)
plt.xlabel(x_axis_label)
plt.ylabel(y_axis_label)
# Overplot the sample averages, with horizontal alignment in the center of each box
for i in range(len(data)):
med = bp['medians'][i]
plt.plot([numpy.average(med.get_xdata())], [numpy.average(data[i])], color='w', marker='s',
markeredgecolor='k')
plt.savefig(file_path + '.png')
plt.close()
您可以使用^{} 来帮助减少文本被截断时遇到的问题。在
plt.tight_layout()
将调整子图参数,以确保所有对象都适合在正确的区域内。在生成绘图时,只需在
plt.show()
之前调用plt.tight_layout()
。在使用
fig.tight_layout
或将一些附加参数传递给savefig
调用。在或者
^{pr2}$相关问题 更多 >
编程相关推荐