【问题标题】:Changing the size of labels of plots in python在python中更改绘图标签的大小
【发布时间】:2019-08-06 21:16:31
【问题描述】:

我正在使用GetDistjupyter 中绘制等高线。我想知道如何更改轴中数字的大小和参数标签。 代码中有几行包含如下标签:

a,b,c = np.genfromtxt('data/data.txt',unpack=True)
names = ['H','M','z']
labels =  ['H','M','z']
samples0 = MCSamples(samples=[a,b,c],names = names, labels = labels)
g.triangle_plot([samples0],['H','M','z'],legend_labels=['Summation of data'], legend_loc='upper right',filled=True)

问题是当参数数量增加时,绘图应该更小以放置在打印纸上,然后我们看不到数字和参数的标签。

谢谢

【问题讨论】:

    标签: python matplotlib plot jupyter-notebook jupyter


    【解决方案1】:

    您可以更改标签的字体大小以调整它们,使它们更加醒目。如果您可以通过添加一些虚拟数据和绘图代码来编辑您的问题以包含MCVE,那么提供更具体的帮助会容易得多。

    【讨论】:

      【解决方案2】:

      您可以使用plot.legend(loc=2, prop={'size': 6}) 来增加图例大小这需要与matplotlib.font_manager.FontProperties 属性对应的关键字字典。 more about legends

      1)。如果您想根据 x 值增加绘图数据的大小,这将很有帮助。

      # yvalues is the y value list widthscale = len(yvalues)/4 figsize = (8*widthscale,6) # fig size in inches (width,height) figure = pylab.figure(figsize = figsize) # set the figsize

      如果你想在没有动态的情况下增加它们,你可以使用plot.rc 函数 例如。

      import matplotlib.pyplot as plt
      
      SMALL_SIZE = 8
      MEDIUM_SIZE = 10
      BIGGER_SIZE = 12
      
      plt.rc('font', size=SMALL_SIZE)          # controls default text sizes
      plt.rc('axes', titlesize=SMALL_SIZE)     # fontsize of the axes title
      plt.rc('axes', labelsize=MEDIUM_SIZE)    # fontsize of the x and y labels
      plt.rc('xtick', labelsize=SMALL_SIZE)    # fontsize of the tick labels
      plt.rc('ytick', labelsize=SMALL_SIZE)    # fontsize of the tick labels
      plt.rc('legend', fontsize=SMALL_SIZE)    # legend fontsize
      plt.rc('figure', titlesize=BIGGER_SIZE)  # fontsize of the figure title
      

      2).第二个选项是

      plt.rcParams["axes.labelsize"] = 22
      

      或者直接控制标签的大小

      ax.set_xlabel("some label", fontsize=22)
      

      要控制图例的字体大小,您可以使用 rcParams

      plt.rcParams["legend.fontsize"] = 22
      

      或者直接在图例中指定大小

      ax.legend(fontsize=22)
      

      【讨论】:

      • 谢谢,但我想更改数字的大小和坐标轴的标签,而不是图例。
      • 那么,为什么我看不到它? figsize? widthscale?标签和名称在哪里?字体?
      • 我已经编辑了答案,我认为我已经给出了您正在寻找的解决方案
      • 是的,但问题是当我将它们放入代码时,代码运行,但输出的情节没有变化
      • 试试第二个选项!!
      【解决方案3】:

      我找到了一个棘手的答案

      g.settings.axes_fontsize = 20
      g.settings.lab_fontsize = 30
      g.settings.x_label_rotation=47
      g.settings.legend_fontsize = 40
      

      通过在GetDist 中使用g.setting,我们可以自定义绘图。

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2014-10-14
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2021-02-26
        • 2019-01-01
        相关资源
        最近更新 更多