<p>From your comment I would take that you already know how to plot contours in python, but are not sure, at what level/height to plot them to get a 1-sigma/68% contour.</p>
<p>The answer you can find, e.g., in table 1 from this paper: <a href="http://articles.adsabs.harvard.edu/pdf/1976ApJ...210..642A" rel="nofollow noreferrer">Avni 1976</a></p>
<p>Essentially, in case of a map of 2 parameters, your <span class="math-container">$\Delta S  = S - S_\mathrm{min}$</span> statistic follows a <span class="math-container">$\chi²$</span> distribution with 2 free parameters. So we want to know how high we have to go in <span class="math-container">$\Delta S$</span>  to include 68% of this distribution. And if you look that up from the <a href="https://en.wikipedia.org/wiki/Chi-squared_distribution" rel="nofollow noreferrer">cumulative  distribution function</a>:
<a href="https://i.sstatic.net/kBqfh.png" rel="nofollow noreferrer"><img src="https://i.sstatic.net/kBqfh.png" alt="enter image description here" /></a></p>
<p>So in conclusiion you will get the 1-sigma contour, if you draw you contours at <span class="math-container">$S_\mathrm{min} + 2.30$</span>.</p>

CC BY-SA 4.0
2021-10-26T08:47:45.980Z
Thank you for clarifying that! I will check out the paper as I have a plot of the cumulative frequency so that is very relevant. Thanks again! I really appreciate your help.
r21
CC BY-SA 4.0
2021-10-25T23:11:27.647Z
2021-10-25T23:11:27.647Z
SpaceCore
<p>I am doing a grid search of omega_Matter vs Omega_dark_energy by iterating over ranges of both and determining the chi-squared to determine the optimal value of both for a LambdaCDM model. I have my grid of omegaM and OmegaDE but I am trying to plot contours at a 68% confidence level and am at a bit of a loss at how to go about doing this.</p>
<p>I am using matplotlib to generate an NxN grid to which the axes correspond to omegaM and omegaDe values and the coordinate points on the grid correspond to the chi-squared of those values. I am then trying to plot a contour plot around the minimum chi-squared value. For now i am using plt.contourf but this doesn't generate specifically 68% confidence contours and therefore I was wondering if there was a specific package in python that did this.</p>
<p>Any help/advice would be greatly appreciated.</p>

CC BY-SA 4.0
2021-10-26T08:46:17.143Z
Thank you for looking into that for me, I completely missed that part of the documentation! I will have a look now. Thanks again for your help.
r21
CC BY-SA 4.0
2021-10-25T16:00:38.257Z
What program are you using? Please specify so unfamiliar users can understand.
WarpPrime
CC BY-SA 4.0
2021-10-25T16:09:25.097Z
Yes my apologies I have been a little scarce on the details. I am using matplotlib to generate an NxN grid to which the axes correspond to omegaM and omegaDe values and the coordinate points on the grid correspond to the chi-squared of those values. I am then trying to plot a contour plot around the minimum chi-squared value. For now i am using plt.contourf but this doesn't generate specifically 68% confidence contours and therefore I was wondering if there was a specific package in python that did this. Hope that makes some more sense. Thank you!
r21
CC BY-SA 4.0
2021-10-25T16:28:13.197Z
Thanks! I've edited your comment into the post.
WarpPrime
CC BY-SA 4.0
2021-10-25T16:29:20.087Z
Ah thank you so much!
r21
CC BY-SA 4.0
2021-10-25T20:54:33.720Z
Googling "`plt.contourf`" returns https://matplotlib.org/stable/api/_as_gen/matplotlib.pyplot.contourf.html and that shows `contourf([X, Y,] Z, [levels], **kwargs)` and scrolling down I see "**levels:** int or array-like, optional Determines the number and positions of the contour lines / regions."
uhoh
<data-analysis>
How to plot 68% contours?
r21
# How to plot 68% contours?

(Asked by: username_0 on 2021-10-25)

I am doing a grid search of omega\_Matter vs Omega\_dark\_energy by iterating over ranges of both and determining the chi-squared to determine the optimal value of both for a LambdaCDM model. I have my grid of omegaM and OmegaDE but I am trying to plot contours at a 68% confidence level and am at a bit of a loss at how to go about doing this.

I am using matplotlib to generate an NxN grid to which the axes correspond to omegaM and omegaDe values and the coordinate points on the grid correspond to the chi-squared of those values. I am then trying to plot a contour plot around the minimum chi-squared value. For now i am using plt.contourf but this doesn't generate specifically 68% confidence contours and therefore I was wondering if there was a specific package in python that did this.

Any help/advice would be greatly appreciated.

**Tags:** data-analysis
> **Comments:**
> **username_1**: What program are you using? Please specify so unfamiliar users can understand.  
> **username_0**: Yes my apologies I have been a little scarce on the details. I am using matplotlib to generate an NxN grid to which the axes correspond to omegaM and omegaDe values and the coordinate points on the grid correspond to the chi-squared of those values. I am then trying to plot a contour plot around the minimum chi-squared value. For now i am using plt.contourf but this doesn't generate specifically 68% confidence contours and therefore I was wondering if there was a specific package in python that did this. Hope that makes some more sense. Thank you!  
> **username_1**: Thanks! I've edited your comment into the post.  
> **username_0**: Ah thank you so much!  
> **username_2**: Googling "`plt.contourf`" returns https://matplotlib.org/stable/api/_as_gen/matplotlib.pyplot.contourf.html and that shows `contourf([X, Y,] Z, [levels], **kwargs)` and scrolling down I see "**levels:** int or array-like, optional Determines the number and positions of the contour lines / regions."  
> **username_0**: Thank you for looking into that for me, I completely missed that part of the documentation! I will have a look now. Thanks again for your help.  

---

## 1 answers

### Answer by username_3 on 2021-10-25. Score: 3 | Accepted answer

From your comment I would take that you already know how to plot contours in python, but are not sure, at what level/height to plot them to get a 1-sigma/68% contour.

The answer you can find, e.g., in table 1 from this paper: [Avni 1976](http://articles.adsabs.harvard.edu/pdf/1976ApJ...210..642A)

Essentially, in case of a map of 2 parameters, your $\Delta S = S - S\_\mathrm{min}$ statistic follows a $\chi²$ distribution with 2 free parameters. So we want to know how high we have to go in $\Delta S$ to include 68% of this distribution. And if you look that up from the [cumulative distribution function](https://en.wikipedia.org/wiki/Chi-squared_distribution):
[![enter image description here](https://i.sstatic.net/kBqfh.png)](https://i.sstatic.net/kBqfh.png)

So in conclusiion you will get the 1-sigma contour, if you draw you contours at $S\_\mathrm{min} + 2.30$.

> **Comments:**
> **username_0**: Thank you for clarifying that! I will check out the paper as I have a plot of the cumulative frequency so that is very relevant. Thanks again! I really appreciate your help.  

---

