GetDist : Set custom axis limits for 2 sigma contours and how to rotate y-labels

Use of Healpix, camb, CLASS, cosmomc, compilers, etc.
Post Reply
Dournac Fabien
Posts: 29
Joined: May 18 2019
Affiliation: IRAP
Contact:

GetDist : Set custom axis limits for 2 sigma contours and how to rotate y-labels

Post by Dournac Fabien » June 02 2020

Hello,

I am trying to do a g.triangle plot with 1 [math] C.L represented by a filled disk and 2 [math] C.L represented by
just contours (without being filled).

Below an example of what I would like to do :

Image

How to achieve this ?

My starting script is :

Code: Select all

g = plots.get_subplot_plotter()
g.settings.figure_legend_frame = True
g.settings.legend_fontsize = 24
g.settings.axes_labelsize = 24
g.settings.axes_fontsize = 20
g.settings.alpha_filled_add = 0.9
g.settings.title_limit_fontsize = 1

g.triangle_plot([matrix1, matrix2],
                names,
        filled = True,
        legend_labels = ['File1', 'File2'],
        contour_colors = ['blue','red']
        )
and the corresponding figure :

Image


As you can see, every confidence levels are represented by filled disks : I just want to have for each paramter a filled disk at CL=1sigma and a contours (without filling) for 2 sigma.

Is it possible ? I tried to apply differents options but without success.
Last edited by Dournac Fabien on June 20 2020, edited 2 times in total.

Antony Lewis
Posts: 1609
Joined: September 23 2004
Affiliation: University of Sussex
Contact:

Re: GetDist : plot filled disk for one sigma and just contours for 2 sigma

Post by Antony Lewis » June 02 2020

You can try explicitly setting the contour colors, eg. something like

Code: Select all

contour_colors=[((1,1,1,0),'red'),((1,1,1,0),'blue')]

Dournac Fabien
Posts: 29
Joined: May 18 2019
Affiliation: IRAP
Contact:

Re: GetDist : plot filled disk for one sigma and just contours for 2 sigma

Post by Dournac Fabien » June 02 2020

Thanks Antony for your quick reply.

I have inserted your option this way :

g.triangle_plot([matrix1, matrix2],
names,
filled = True,
legend_labels = ['Standard case FoM = 1239.43', ['Extended FoM = 1565.86'],
#contour_colors = ['red','blue'],
contour_colors=[((1,1,1,0),'red'),((1,1,1,0),'blue')]
)

and it produces 2 cases for subplots generated (good and bad).

1) For the first one, here an example :

Image

The pink zone is alpha transparent (since the blue contour is outside this red zone) : it is the expected result that I wanted

2) For the second one, here an example :

Image

All the disk corresponding to 1 sigma is pink, impossible to make it display in red (since blue contours is outside of this red disk).

I would like in this case, that portion which is bigger than blue filled disk, to be displayed in red, even if the blue 2 sigma contour is outside of this pink zone (actually, pink should be red and not pink)

Conclusion : I have to find a way to set priority between zones that overlap themselves for filled disks (more generally filled contours).

Anyone could help me to find this trick ?

Regards

Dournac Fabien
Posts: 29
Joined: May 18 2019
Affiliation: IRAP
Contact:

Re: GetDist : plot filled disk for one sigma and just contours for 2 sigma

Post by Dournac Fabien » June 02 2020

Given the fact that I am plotting 2 covariance matrixes, i.e :

Code: Select all

matrix1 = GaussianND(mean, COV_File1, labels = labels, names = names)
matrix2 = GaussianND(mean, COV_File2, labels = labels, names = names)
So I tried to use contour_colors by specifying 4 colors ( 2 per matrix, first for 1 [math] and second for 2 [math]) like this :

Code: Select all

contour_colors=[((1,1,1,0),'red'),((1,1,1,0),'blue'),((1,1,1,0),'red'),((1,1,1,0),'blue')]


But it seems useless in my case, it doesn't change anything towards my above issue for pink zone that sould be red when blue line contours is outside this pink filled zone.

Another suggestion to try ?

Dournac Fabien
Posts: 29
Joined: May 18 2019
Affiliation: IRAP
Contact:

Re: GetDist : plot filled disk for one sigma and just contours for 2 sigma

Post by Dournac Fabien » June 02 2020

I must precise what I would like to get. The following figure represents the sub-plot of the block (w0,wa) :

Image

I just want to have the same colors except the light magenta/purple which sould be blue like the contour of 2 sigma outside of every zone.

For the moment, I tried to play with the option

Code: Select all

settings.alpha_filled_add
and

Code: Select all

alpha_factor_contour_lines
, even coupled with Antony's suggestion :

Code: Select all

 contour_colors=[((1,1,1,0),'blue'),((1,1,1,0),'red')]
Unfortunately, it fails when the red "2 sigma contour" is bigger than the blue "1 sigma contour" : there is automatically a transparency effect that is applied by GetDist, so that explains why the color is light magenta/purple instead of blue.

Regards

Dournac Fabien
Posts: 29
Joined: May 18 2019
Affiliation: IRAP
Contact:

Re: GetDist : plot filled disk for one sigma and just contours for 2 sigma

Post by Dournac Fabien » June 02 2020

and other precision : if I take on the same triangle_plot the block (h,sig8), I get the following subplot :

Image

As you can see, display results for the different area/contours are logical, since the red "2 sigma" doesn't not fully contain the blue "1 sigma filled disk", that's why we see the normal blue area upper and lower, and logically, color is light magenta/purple when overlapping between the red "2 sigma" and blue "1 sigma" disk.

That's why, compared to the other situation in previous post, there should be a condition on the "entire presence of a disk inside another one" to make appear or not the blue color and not the light magenta/purple in this special case. Hoping you will understand this specific problem.

Thanks

Dournac Fabien
Posts: 29
Joined: May 18 2019
Affiliation: IRAP
Contact:

Re: GetDist : Set custom axis limits for 2 sigma contours and how to rotate y-labels

Post by Dournac Fabien » June 20 2020

Hello,

I am trying to do a g.triangle plot with 1 [math] C.L represented by a filled disk and 2 [math] C.L represented by
just contours (without being filled).

Below an example of what I would like to do :

Image

How to achieve this ?

My starting script is :

Code: Select all

g = plots.get_subplot_plotter()
g.settings.figure_legend_frame = True
g.settings.legend_fontsize = 24
g.settings.axes_labelsize = 24
g.settings.axes_fontsize = 20
g.settings.alpha_filled_add = 0.9
g.settings.title_limit_fontsize = 1

g.triangle_plot([matrix1, matrix2],
                names,
        filled = True,
        legend_labels = ['File1', 'File2'],
        contour_colors = ['blue','red']
        )
and the corresponding figure :

Image


As you can see, every confidence levels are represented by filled disks : I just want to have for each paramter a filled disk at CL=1sigma and a contours (without filling) for 2 sigma.

Is it possible ? I tried to apply differents options but without success.
Hello,

I made progress from the previous post above.

I can zoom in the contours for each subplot, illustrated by the figure below :

Image

Now, I would like to continue to improve this plot by doing :

1) Make the y-axis labels horizontal (b,c,d,e,f,g) of the triangle plot.

1.1) FIRST TRY, I have tested with :

Code: Select all

g = plots.get_subplot_plotter()
g.settings.figure_legend_frame = True
g.settings.legend_fontsize = 22
g.settings.axes_labelsize = 22
g.settings.axes_fontsize = 20
# Important parameter : width of 2D contour lines
g.settings.lw_contour = 4
g.settings.title_limit_fontsize = 1
g.settings.axis_tick_x_rotation = 60

# FIRST TRY : Rotate y-axis label to make them horizontal
g.rotate_yticklabels = 90
but the rotation of y-labels is not performed.

1.2) SECOND TRY :

Code: Select all

g.triangle_plot([matrix1, matrix2],
                names,
                filled = True,
                legend_labels = ['FoM = 1240', 'FoM = 1560'],
                legend_loc = 'upper right',
                contour_colors = ['red','darkblue'],
                line_args = [{'lw':2, 'color':'red'},
                {'lw':2, 'color':'darkblue'}],
                # SECOND TRY : Rotate y-axis label to make them horizontal
                rotate_yticklabels = 90
                )
not also working .

1.3) and finally tried :

Code: Select all

  plt.yticks(rotation='horizontal')
same thing, no rotation carried out.

2) Secondly, I would like to set custom x-ticks values (actually only 3 values, the mean and the minimum/maximum of contours projected from the x-axis delimited by red ellipse (representing 95% C.L = 2 sigma).

I did a test with the following instructions :

Code: Select all

for k in range(0,7):
  # Get axis
  ax = g.subplots[k, k]
  # Caution : inevitably, minorx will be equal to 0
  #           for likelihood
  min_majorx = major_proj_xaxis[1, k]
  min_minorx = minor_proj_xaxis[1, k]

  # Take the min for major and minor axis of red ellipse
  ax.set_xlim(mean[k] - factor_zoom*min_majorx, mean[k] + factor_zoom*min_majorx)

  # TRY to set custom limits for xtick, minimum and maximum of the x-values of red contours and the mean, so 3 xticks for each sublplot.
  ax.xticks([-0.1, 0,  0.1])
the bounds values [-0.1, 0, 0.1] are just testing values. How to set manually values with the associated xtick and label ?

If someone could see how to enhance these 2 specifications (point 1) and 2)), I woud really appreciate.

Regards

Antony Lewis
Posts: 1609
Joined: September 23 2004
Affiliation: University of Sussex
Contact:

Re: GetDist : Set custom axis limits for 2 sigma contours and how to rotate y-labels

Post by Antony Lewis » June 21 2020

Use

Code: Select all

g.settings.axis_tick_y_rotation 
to change y rotation.

You can access g.subplots[a,b] to get an Axes instance to do whatever you like with it using standard matplotlib.

Dournac Fabien
Posts: 29
Joined: May 18 2019
Affiliation: IRAP
Contact:

Re: GetDist : Set custom axis limits for 2 sigma contours and how to rotate y-labels

Post by Dournac Fabien » June 21 2020

Thanks Antony,

my question is not about the yticks rotation but the y-labels rotation : by default, they are vertical, I would like to make render them horizontal.

Here below what I have got right now with :

Code: Select all


g.settings.axis_tick_y_rotation = 45
Result :

Image

As you can see on x-axis, labels are horizontal ([math]) and I would like the same for labels on y-axis.

I tried to do :

Code: Select all

g.rotate_yticklabels = 90
without success

How can I rotate these y-axis labels ([math]) ?

Thanks

Darshan Beniwal
Posts: 2
Joined: March 17 2020
Affiliation: Department of Physics and Astrophysics, University of Delhi, Delhi, India

Re: GetDist : Set custom axis limits for 2 sigma contours and how to rotate y-labels

Post by Darshan Beniwal » June 21 2020

Dear Dournc.

I can give you hint to fix it.
To print Y-label horizontally, we have to set rotate Y-label instead of Y-ticks. If somehow you can set something like y label rotation=0.0, then it will defiently gives an horizontal label text. You may follow [ https://getdist.readthedocs.io/en/latest/_modules/getdist/plots.html ] to see its source code and from there I hope you can pass required command into your code.
Sorry I can't provide the exact command for the same. I tried to set it in my trail code but couldn't.

Sincerely.

Antony Lewis
Posts: 1609
Joined: September 23 2004
Affiliation: University of Sussex
Contact:

Re: GetDist : Set custom axis limits for 2 sigma contours and how to rotate y-labels

Post by Antony Lewis » June 22 2020

You'd have to use standard matplotlib commands to rotate the axis labels, there's no built-in support for triangle plots.

Post Reply