python - 如何使 x 和 y 轴标签的文本大小以及 matplotlib 和 prettyplotlib 图形上的标题更大

标签 python matplotlib pandas prettyplotlib

我将 matplotlib 或 prettyplotlib 图的图形大小设置得很大。 例如,假设尺寸为 80 高 x 80 宽。

绘图标题、x 和 y 轴标签(即点标签 2014-12-03 和轴标签 [month of year])的文本大小变得非常小,以至于无法阅读。

如何增加这些文本标签的大小?现在我必须使用网络浏览器放大才能看到它们。

enter image description here

最佳答案

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)

例子:

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

enter image description here

------------ 编辑------------

使用漂亮的情节

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) 

------------图例----------------

使用prop属性

ppl.legend(prop={'size':20})
plt.legend(prop={'size':20})

同样的命令..


例子:

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

enter image description here

关于python - 如何使 x 和 y 轴标签的文本大小以及 matplotlib 和 prettyplotlib 图形上的标题更大,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27350226/

相关文章:

python - 将 Pandas 数据框转换为列表

python - 迭代由不同数据帧组成的列表

python - 如何为 Jupyter 中的每个单元格设置 matplotlib 的 DPI

python - 如何从 Django 发推文?

Python 正则表达式 : User Inputs Multiple Search Terms

python - 如何在给定实际坐标的情况下生成 matplotlib 填充等高线图的数据?

python - 具有不断变化的 y 值的 Matplotlib 热图

python - 根据 2 列值过滤数据框

python - python的dict构造函数是如何处理Mappings的?

python - .json 扩展文件 + 时间戳 + Pandas + Python