pandas 如何使 x 和 y 轴标签的文本大小以及 matplotlib 和 prettyplotlib 图形上的标题更大
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/27350226/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
how to make the text size of the x and y axis labels and the title on matplotlib and prettyplotlib graphs bigger
提问by yoshiserry
I set the figure size of a matplotlib or prettyplotlib graph to be large. As an example lets say the size is 80 height by 80 width.
我将 matplotlib 或 prettyplotlib 图形的图形大小设置为大。例如,假设大小为 80 高 x 80 宽。
The text size for the plot title, x and y axis labels (i.e. point label 2014-12-03 and axis label [month of year] become very small to the point they are unreadable.
绘图标题、x 和 y 轴标签(即点标签 2014-12-03 和轴标签 [month of year])的文本大小变得非常小,以至于无法阅读。
How do I increase the size of these text labels? Right now I have to zoom in with the web browser to see them.
如何增加这些文本标签的大小?现在我必须用网络浏览器放大才能看到它们。


回答by Jo?o Paulo
The sizeproperty:
该size属性:
import matplotlib.pyplot as plt
plt.xlabel('my x label', size = 20)
plt.ylabel('my y label', size = 30)
plt.title('my title', size = 40)
plt.xticks(size = 50)
plt.yticks(size = 60)
Example:
例子:
import numpy as np
import matplotlib.pyplot as plt
mu, sigma = 100, 15
x = mu + sigma * np.random.randn(10000)
n, bins, patches = plt.hist(x, 50, normed=1, facecolor='g', alpha=0.75)
plt.xlabel('Smarts', size = 20)
plt.ylabel('Probability')
plt.title('Histogram of IQ', size = 50)
plt.text(60, .025, r'$\mu=100,\ \sigma=15$', size = 30)
plt.axis([40, 160, 0, 0.03])
plt.xticks(size = 50)
plt.yticks(size = 50)
plt.grid(True)
plt.show()


---------- EDIT --------------
- - - - - 编辑 - - - - - - -
using pretty plot
使用漂亮的情节
fig, ax = plt.plot()
fig.suptitle('fig title', size = 80)
ax.set_title('my title', size = 10)
ax.set_xlabel('my x label', size = 20)
ax.set_ylabel('my y label', size = 30)
for tick in ax.xaxis.get_major_ticks():
tick.label.set_fontsize(40)
for tick in ax.yaxis.get_major_ticks():
tick.label.set_fontsize(50)
--------- LEGEND --------------
- - - - - 传奇 - - - - - - -
use the propproperty
使用prop财产
ppl.legend(prop={'size':20})
plt.legend(prop={'size':20})
same command..
同样的命令..
example:
例子:
import matplotlib.pyplot as plt
import matplotlib as mpl
from prettyplotlib import brewer2mpl
import numpy as np
import prettyplotlib as ppl
np.random.seed(12)
fig, ax = plt.subplots(1)
fig.suptitle('fig title', size = 80)
ax.set_title('axes title', size = 50)
for tick in ax.xaxis.get_major_ticks():
tick.label.set_fontsize(60)
ax.set_ylabel("test y", size = 35)
for i in range(8):
y = np.random.normal(size=1000).cumsum()
x = np.arange(1000)
ppl.plot(ax, x, y, label=str(i), linewidth=0.75)
ppl.legend(prop={'size':30})
fig.savefig('plot_prettyplotlib_default.png')



