GetDist : make appear mean values for contours on both x-axis and y-axis

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

GetDist : make appear mean values for contours on both x-axis and y-axis

Post by Dournac Fabien » May 14 2020

Hi,

I have an example of triplot (using triangle_plot) which is deduced from a Covariance matrix to get the contours of considered parameters.

Here the script :

Code: Select all

# Show plots inline, and load main getdist plot module and samples class
from __future__ import print_function
import sys, os
sys.path.insert(0,os.path.realpath(os.path.join(os.getcwd(),'..')))
import numpy as np
import getdist 
from getdist import plots
import matplotlib.pyplot as plt
import matplotlib as mpl
# The plotting scripts also let you plot Gaussian (or Gaussian mixture) contours 
from getdist.gaussian_mixtures import GaussianND
from getdist.gaussian_mixtures import Mixture2D
print('GetDist Version: %s, Matplotlib version: %s'%(getdist.__version__, plt.matplotlib.__version__))

## Load Fisher matrix and invert it to get Covariance array
# Load Fisher matrix
File1 = np.loadtxt('File1.dat')
# Invert to get Covariance matrix
COV_File1 = np.linalg.inv(File1)[0:7,0:7]

# Mean of each cosmo parameters : respect order of generated "Big" Fisher matrix
mean = [0.32, 0.05, -1.0, 0.0, 0.96, 0.67, 0.815] 

# Names and labels
names = ['Omega_m', 'Omega_b', 'w_0', 'w_a', 'h', 'n_s', 'sigma_8']
labels = [r'\Omega_{m}', r'\Omega_{b}', r'w_{0}', r'w_{a}', r'h', r'n_{s}', r'\sigma_{8}']

# Current method
matrix1 = GaussianND(mean, COV_File1, labels = labels, names = names)

# Plot triplot
plt.rcParams['text.usetex'] = True
plt.rc_context({'axes.autolimit_mode': 'round_numbers'})
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.axis_tick_x_rotation = 45
g.settings.axis_tick_y_rotation = 45
g.settings.alpha_filled_add = 0.9
g.settings.title_limit_fontsize = 1

g.triangle_plot(matrix1, 
                names,
		filled = True,
		legend_labels = ['File1'], 
        contour_colors = ['green']
		)
# Save triplot
g.export('output_example.png')
Below the plot :

Image

As you can see, the mean for each of the parameter is not systematically displayed on both axis (x-axis and y-axis) : especially, on y-axis, the mean for [math] is shown whereas on x-axis, I have just an interval and not the mean.

For Hubble parameter [math], I have just an interval for both axis. Same issue with [math] and [math] parameters.

Concerning the other parameters, everything is working fine. So what's wrong to make print these missing mean values on both axis for a triangle plot ?

Any suggestion/clue is welcome. Regards

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

Re: GetDist : make appear mean values for contours on both x-axis and y-axis

Post by Darshan Beniwal » May 15 2020

Hi Fablen

As per my understanding your issue, I think you want to print mean value of each parameter.
If so, then please just replace your code line

Code: Select all

g.triangle_plot(matrix1, 
                names,
		filled = True,
		legend_labels = ['File1'], 
        contour_colors = ['green']
		)
to

Code: Select all

g.triangle_plot(matrix1, 
                names,
                line_args=[{'ls':'--', 'color':'green'},
               {'lw':2, 'color':'darkblue'}], 
    contour_colors=['green','darkblue'],
    title_limit=1, 
		filled = True,
		legend_labels = ['File1'], 
        contour_colors = ['green']
		)
I hope this helps you.

Sincerely.

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

Re: GetDist : make appear mean values for contours on both x-axis and y-axis

Post by Dournac Fabien » May 15 2020

Hi Darshan Beniwa,

Thanks for your quick answer. Unfortunately, your suggestion is not working, I get the following error at execution with :

Code: Select all

g.triangle_plot(matrix1,
                names,
                line_args=[{'ls':'--', 'color':'green'},
                {'lw':2, 'color':'darkblue'}],
                contour_colors=['green','darkblue'],
                title_limit=1,
                filled = True,
                legend_labels = ['File1'],
                contour_colors = ['green']
               )
Error :

Code: Select all

  File "example_cosmocoffee_mean_issue_answer.py", line 84
    contour_colors = ['green']
    ^
SyntaxError: keyword argument repeated
If I delete this line

Code: Select all

contour_colors = ['green']
, I get another error :

Code: Select all

Traceback (most recent call last):
  File "example_cosmocoffee_mean_issue_answer.py", line 83, in <module>
    legend_labels = ['File1'],
  File "/Users/fab/Library/Python/3.7/lib/python/site-packages/getdist/plots.py", line 2398, in triangle_plot
    lims=param_limits.get(param.name), ax=ax, _ret_range=True, **diag1d_kwargs)
  File "/Users/fab/Library/Python/3.7/lib/python/site-packages/getdist/plots.py", line 1558, in plot_1d
    ax=ax, **line_args[i])
  File "/Users/fab/Library/Python/3.7/lib/python/site-packages/getdist/plots.py", line 968, in add_1d
    raise ValueError('title_limit not currently supported for MixtureND')
[b]ValueError: title_limit not currently supported for MixtureND[/b]
This error was expected from what Antony told me in a previous post : no support of title_limit for MixtureND.

So, I have deleted also this line

Code: Select all

title_limit=1
such the code snippet looks like :

Code: Select all

g.triangle_plot(matrix1,
                names,
                line_args=[{'ls':'--', 'color':'green'},
                {'lw':2, 'color':'darkblue'}],
                contour_colors=['green','darkblue'],
                filled = True,
                legend_labels = ['File1'],
               )
Here the plot generated :

Image

As you can see, some mean values on both axes are missing ( on x-axis : [math]

and on y-axis : [math].

What I don't understand is that for [math] parameter, its mean is displayed (=0.96) on y-axis and not on the x-axis : this is the only difference between the 2 axes : where could this strange behavior come from ?


So, debugging to display the mean for all parameters continues. Any other suggestion would be fine.

Regards

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

Re: GetDist : make appear mean values for contours on both x-axis and y-axis

Post by Antony Lewis » May 18 2020

The axis tick labels are in general unrelated to the mean on both axes (even for n_s the mean is not exactly 0.96). You can show means and errors in latex above each parameter if you want to (title_limit option).

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

Re: GetDist : make appear mean values for contours on both x-axis and y-axis

Post by Dournac Fabien » May 18 2020

Hi Antony,

I have already used the option title_limit on this previous post : viewtopic.php?f=11&t=3319&p=9078#p9078

and I got the following error :

Code: Select all

ValueError: title_limit option  not currently supported for MixtureND
You told me that error was normal since title_limit is only supported for Gaussian mixturess.

If you look at my previous snippet code, I tried as suggested by @Darshan Beniwa told me, i.e :

Code: Select all

g.triangle_plot(matrix1, 
                names,
                line_args=[{'ls':'--', 'color':'green'},
               {'lw':2, 'color':'darkblue'}], 
               contour_colors=['green','darkblue'],
                title_limit=1, 
		filled = True,
  		legend_labels = ['File1'], 
                contour_colors = ['green']
		)
and so following error :

Code: Select all

raise ValueError('title_limit not currently supported for MixtureND')
   ValueError: title_limit not currently supported for MixtureND
Do you agree ?

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

Re: GetDist : make appear mean values for contours on both x-axis and y-axis

Post by Antony Lewis » May 18 2020

Yes, title_limit is only with samples.

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

Re: GetDist : make appear mean values for contours on both x-axis and y-axis

Post by Dournac Fabien » May 18 2020

Sorry Antony, I just want to place on both axis the fiducial values contained into the following array :

Code: Select all

# Mean of each cosmo parameters : respect order of generated "Big" Fisher matrix
mean = [0.32, 0.05, -1.0, 0.0, 0.96, 0.67, 0.815] 
Indeed, in my code snippet, I provide this array

Code: Select all

mean
into GaussianND :

Code: Select all

# Current method
matrix1 = GaussianND(mean, COV_File1, labels = labels, names = names)
Isn't there really a way to display these fiducial values for each subplot ? I can't convert a Sample into Covariance matrix ^^.

Regards

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

Re: GetDist : make appear mean values for contours on both x-axis and y-axis

Post by Antony Lewis » May 19 2020

You can access the g.subplots array directly and add titles etc as you like. You can also use the 'markers' argument to add lines marking the mean values.

Post Reply