python - 设置所有子图中刻度的大小

标签 python python-2.7 matplotlib

我有一个带有几个子图的 plt.figure(...),我的代码基本上是这样的:

num_plots = 2

my_dpi = 96 
fig_size = (1440 / my_dpi, 900 / my_dpi)

fig = plt.figure(figsize=fig_size, dpi=my_dpi, frameon=False)

# Subplot 1
fig.add_subplot(num_plots, 1, 1)
# plot fancy stuff

# Subplot 2
fig.add_subplot(num_plots, 1, 2)
# plot fancy stuff

我想要的是类似的东西

fig.get_all_subplots.xtick(size='small')

感谢您的支持!

编辑:

我认为它应该是 plt.get_all_subplots 而不是 fig.get_all_subplots

最佳答案

您可以在这里做两件事。如果要更改正在运行的脚本中所有图形的刻度大小,则需要在代码顶部添加以下内容:

import matplotlib

matplotlib.rc('xtick', labelsize=20) 
matplotlib.rc('ytick', labelsize=20) 

这对于您当前的代码就足够了,因为只有一个图。但是,如果您有多个绘图但只想更改特定图形的刻度大小,则可以使用 plt.tick_params,例如:

import matplotlib.pyplot as plt

fig,ax = plt.subplots()
plt.plot(x,y)
plt.xlabel('Time')
plt.ylabel('Temperature')
plt.tick_params(axis='both', which='major', labelsize=22)

关于python - 设置所有子图中刻度的大小,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38369188/

相关文章:

python - pyplot 图表上光标位置的详细日期

python - 如何使用 Python 的 matplotlib 绘制 map 以便也包括小岛国?

python - 纯 Python Tidy 类应用程序/库

python - 使用 Pandas 如何根据日期查找列中某些元素的平均值?

python - 将 crontab 与 django 一起使用

python - 如何将某物称为对象而不是列表?

python - python 列表理解中的 if-else

python regular express 如何获取一个值,该值将由 "&page=2"处理或不能处理

python - 使用 pandas 创建 matplotlib 多系列线图

python - 从同一目录检索多个文件