【问题标题】:Matplotlib : Impossible to set 0.0 and 1.0 on right ytick values outside a subplotMatplotlib:不可能在子图外的右 ytick 值上设置 0.0 和 1.0
【发布时间】:2020-12-29 16:00:49
【问题描述】:

我正在尝试在子图的右 y 轴上显示 yticks 0.01.0(而不是 01

这是我所做的(使用mn 图表的行/列):

 ax = g.subplots[m,n]
 ax.yaxis.tick_right()
 ax.yaxis.set_ticks_position('right')
 ax.set_yticks([float(0), float(1)])

结果是:

我认为这会与红色的上标题冲突,但即使我采用较小的字体大小,prollem 仍然存在,无法显示0.01.0 而不是01

上图表示来自具有联合分布的协方差矩阵的 1/2 sigma 置信水平。由 Getdist tool制作。

生成此图的主要程序是:

g.triangle_plot([matrix1, matrix2],
                  names,
                  filled = True,
                  legend_labels = ['1240', '1560'],
                  legend_loc = 'upper right',
                  contour_colors = ['darkblue','red'],
                  line_args = [{'lw':2, 'color':'darkblue'},
                  {'lw':2, 'color':'red'}]
                  )

之后,我通过双循环修改每个框:

# Browse each subplot of triangle
  for m in range(0,7):
    for n in range(0,m+1):
      ax = g.subplots[m,n]
      ax.tick_params(axis='both', direction='out', length=5, width=1)

我做了我在帖子开头展示的内容:

 ax.yaxis.tick_right()
 ax.yaxis.set_ticks_position('right')
 ax.set_yticks([float(0), float(1)])

【问题讨论】:

  • @TrentonMcKinney 我已经添加了主要功能和我在 GetDist 工具中使用的额外功能。

标签: python numpy precision xticks


【解决方案1】:

你可以使用set_yticklabels(['0.0', '1.0'])

【讨论】:

    猜你喜欢
    • 2022-07-08
    • 1970-01-01
    • 1970-01-01
    • 2017-02-20
    • 2015-05-20
    • 2014-07-08
    • 2021-01-27
    • 2019-08-04
    • 2018-08-29
    相关资源
    最近更新 更多