【问题标题】:how to change the size of the sci notation above the y axis in matplotlib?如何更改 matplotlib 中 y 轴上方 sci 符号的大小?
【发布时间】:2012-12-19 01:05:48
【问题描述】:

如何改变matplotlib中y轴上方sci符号的大小?

以下是四个子图的基本代码和图像,我不知道如何减小 y 轴上方的 sci 幂符号的大小。

任何建议将不胜感激

import matplotlib.pyplot as plt
import numpy as np

def plot():
    #plot data
    ax.plot(np.arange(0,10000,100),np.arange(0,10000,100))

    #set label style        
    ax.ticklabel_format(style='sci',axis='y')
    ax.yaxis.major.formatter.set_powerlimits((0,0))

    #format labels/ticks
    ax.tick_params(axis='x',tick1On=True, tick2On=False, label1On=True,
        label2On=False, labelsize=7,color='black')
    ax.tick_params(axis='y', tick1On=True,tick2On=False, label1On=True,
        label2On=False, labelsize=7,color='black')

fig = plt.figure()
ax = fig.add_subplot(2,2,1)
plot()

ax = fig.add_subplot(2,2,2)
plot()

ax = fig.add_subplot(2,2,3)
plot()

ax = fig.add_subplot(2,2,4)
plot()

plt.tight_layout()
fig.subplots_adjust(left=None, bottom=None, right=None, wspace=0.15, hspace=0.22)

plt.show()

【问题讨论】:

    标签: python matplotlib font-size


    【解决方案1】:

    添加这一行:

    plt.rc('font', **{'size':'30'})
    

    更改 y 轴上方的字体大小。 30 使文本明显更大,但我假设您想与轴标签等匹配,因此您需要大约 6-8 的内容。这实际上会改变其他文本字体大小(虽然不是轴标签或刻度标签)。

    【讨论】:

    • 太棒了 - 做到了!我没有来 plt.rc() 。非常感谢
    【解决方案2】:

    使用 Matplotlib 的 AxisArtist 容器的 offsetText 属性表示功率。要将字体大小更改为power_fontsize,您可以这样做

    ax.yaxis.get_offset_text().set_fontsize(power_fontsize)
    

    对于代码中ax 的每个实例。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-10-17
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多