Search code examples
pythonnumpyprecisionxticks

Matplotlib : Impossible to set 0.0 and 1.0 on right ytick values outside a subplot


I am trying to display the yticks 0.0 and 1.0 on right y axis of a subplot (instead of 0 and 1)

Here what I have done (with m and n the rows/columns of graph) :

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

and the result is :

plot

I thought that it would be a conflict with the red upper title but even if I take a smaller font size, prollem remains, impossible to make display 0.0 and 1.0 instead of 0 and 1.

The plot above represents the 1/2 sigma confidence levels coming from a covariance matrix with joint distributions. It is produced by Getdist tool.

The main routine that generates this plot is :

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

and after, I modify each box by doing the double loop :

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

in which I did what I have shown at the beginning of my post :

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

Solution

  • You could use set_yticklabels(['0.0', '1.0'])