# Uq\_display\_uq\_inversion: Determine limits for scatter plots for posteriori samples from the posteriori samples instead of using prior samples (at least, if there no prior samples)

**URL:** <https://uqworld.org/t/uq-display-uq-inversion-determine-limits-for-scatter-plots-for-posteriori-samples-from-the-posteriori-samples-instead-of-using-prior-samples-at-least-if-there-no-prior-samples/1141>\
**Category:** Feature Requests\
**Created:** [April 13, 2021, 2:38pm UTC](https://uqworld.org/t/uq-display-uq-inversion-determine-limits-for-scatter-plots-for-posteriori-samples-from-the-posteriori-samples-instead-of-using-prior-samples-at-least-if-there-no-prior-samples/1141 "2021-04-13T14:38:17Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![olaf.klein](https://uqworld.org/user_avatar/uqworld.org/olaf.klein/32/468_2.png) [@olaf.klein](https://uqworld.org/u/olaf.klein)\
**Post date:** [April 13, 2021, 2:38pm UTC](https://uqworld.org/t/uq-display-uq-inversion-determine-limits-for-scatter-plots-for-posteriori-samples-from-the-posteriori-samples-instead-of-using-prior-samples-at-least-if-there-no-prior-samples/1141/1 "2021-04-13T14:38:17Z")

</div>

Dear @paulremo , dear all,

In UQLab 1.4, the values given as parameter for` 'Limits'` limits are no longer ignored by the function `uq_scatterDensity`, such that the values in the corresponding calls to this function in `uq_display_uq_inversion` are now used during the creation of the scatter plot.

I am not sure, if this is a planed behavior or an error, but it holds that the limits for the scatter plots for the prior samples **and** for the posterior sample are **both** computed from the **prior samples**. In UQLab 1.3 these values were ignored by `uq_scatterDensity`, but this is no longer the case in UQLab 1.4, as one can observe e.g. by considering the scatter plots in the 1.4.version of `UserManual_Bayesian.pdf`. In these plots, the plot ranges in the prior plot and in the posterior plots are the same, see also my version of the scatter plots in Figure 9:  
 ![fig-9-scatter-prior](https://uqworld.org/uploads/default/original/1X/88f5f26d763917d4893f20e0a8ab6456bf6e29b7.png)  
 ![fig-9-scatter-posterior-org](https://uqworld.org/uploads/default/original/1X/6399b6e96ccfd66ccc5122a9f10ab551d7a9016f.png)

I do not like this **same plot limits approach,** since the variation of the posterior samples  
(after removing the burn-In phase and maybe also bad chains) may be much smaller then the  
variation of the prior samples and are invisible in plots using the limits determined from  
the prior samples. Therefore, I have replaced in my copy of `uq_display_uq_inversion`.m  
in the line 297 `allPlotPoints = [PriorSample; plotPointCollection];` by `allPlotPoints = [PostSample; plotPointCollection];`. Thanks to this modification, the resulting scatter plot for the posterior samples changed to

![fig-9-scatter-posterior](https://uqworld.org/uploads/default/original/1X/0148265902dd73c646f46517723418e2cfbfef42.png)

In contrast to the posterior scatter plot above, one can really see the variation of E.

Hence, I suggest to perform this change also in the official version of `uq_display_uq_inversion` and to replace in line 314 `'Limits', [min(PriorSample);max(PriorSample)],...` by  
`'Limits', [min(PostSample);max(PostSample)],...` .

If this same plot limits approach behavior is planed, I would suggest to add to the flags considered in [Further plot possibilities for results of Bayesian inversion (Suggestions and code example) - #2 by paulremo](https://uqworld.org/t/further-plot-possibilities-for-results-of-bayesian-inversion-suggestions-and-code-example/1105/2) a flag like ‘scatter.reusePriorlimits’ that allows to activate/ deactivate this approach.

Greetings  
Olaf

---

<div class="post-metadata">

**Author:** ![paulremo](https://uqworld.org/user_avatar/uqworld.org/paulremo/32/192_2.png) [@paulremo](https://uqworld.org/u/paulremo)\
**Post date:** [April 14, 2021, 7:41am UTC](https://uqworld.org/t/uq-display-uq-inversion-determine-limits-for-scatter-plots-for-posteriori-samples-from-the-posteriori-samples-instead-of-using-prior-samples-at-least-if-there-no-prior-samples/1141/2 "2021-04-14T07:41:28Z")

</div>

Hi @olaf.klein

This behavior is indeed on purpose to show the information gain from updating. However, I agree with you that a flag option would make more sense to allow visual inspection of the posterior distribution in cases of large information gain, like the one you mention in your post.

Can you add a reference to this post to the original post [here](https://uqworld.org/t/further-plot-possibilities-for-results-of-bayesian-inversion-suggestions-and-code-example/1105/2)?

---

<div class="post-metadata">

**Author:** ![olaf.klein](https://uqworld.org/user_avatar/uqworld.org/olaf.klein/32/468_2.png) [@olaf.klein](https://uqworld.org/u/olaf.klein)\
**Post date:** [May 2, 2022, 4:13pm UTC](https://uqworld.org/t/uq-display-uq-inversion-determine-limits-for-scatter-plots-for-posteriori-samples-from-the-posteriori-samples-instead-of-using-prior-samples-at-least-if-there-no-prior-samples/1141/3 "2022-05-02T16:13:48Z")

</div>

Dear @paulremo, dear all,

since there no flag-option based solution has been released until now, I would like to suggest a change of ` uq_display_uq_inversion_MCMC.m` that allows to **switch** between **both** kinds of determine plot limits by simply adapting the content of `myBayesianAnalysis`, i.e.the module/object being the input for ` uq\_display\_uq\_inversion\_MCMC.m, see my file [uq\_display\_uq\_inversion\_MCMC.m](https://uqworld.org/uploads/short-url/4FxN5n5J3TUevFVq7QqhTHjZZBM.m) (22.1 KB)

As long as one has a `.PriorSample` component in the `...Results.Postproc` structure, the limits of this fields are also used to determine the boundaries for plots for the posterior samples, But, if this component does not exists, i.e. if one has performed  
`uq_postProcessInversion(myBayesianAnalysis,'priorPredictive',0);`,  
then the scatter plots for the posterior samples are adapt to the limits of this samples.

I have just replaced the line 328

```matlab
 plotLimits = [min(allPlotPoints); max(allPlotPoints)];

```

by

```matlab
 if procPriorSample_avail
       allPlotPoints = [PriorSample; plotPointCollection];
  else
       allPlotPoints = [PostSample; plotPointCollection];
  end

```

and 337-343

```matlab
  uq_scatterDensity(...
            gca,...
            PostSample,...
            'Labels', paramLabelsScatter,...
            'Color', postColor,...
            'Limits', [min(PriorSample);max(PriorSample)],...
            'Title', 'Posterior Sample');

```

by

```matlab
   if procPriorSample_avail
         plotLimits = [min(PriorSample);max(PriorSample)];
    else
        plotLimits = [min(PostSample);max(PostSample)];
    end
    uq_scatterDensity(...
            gca,...
            PostSample,...
            'Labels', paramLabelsScatter,...
            'Color', postColor,...
            'Limits', plotLimits,...
            'Title', 'Posterior Sample');

```

In this is changed, one can also create scatter plots also if no prior samples are  
available. According to a remark on page 72 of the documentation this should be possible, but currently I get an error message if I try to do this.

Greetings

Olaf

---

<div class="post-metadata">

**Author:** ![paulremo](https://uqworld.org/user_avatar/uqworld.org/paulremo/32/192_2.png) [@paulremo](https://uqworld.org/u/paulremo)\
**Post date:** [May 5, 2022, 9:23pm UTC](https://uqworld.org/t/uq-display-uq-inversion-determine-limits-for-scatter-plots-for-posteriori-samples-from-the-posteriori-samples-instead-of-using-prior-samples-at-least-if-there-no-prior-samples/1141/4 "2022-05-05T21:23:22Z")

</div>

Dear @olaf.klein

Thanks for reporting this potential bug! I am no longer an active developer for UQLab, but I reported the issue to the current development team and they will have a look as soon as possible. I also informed them of the flag option you suggested to allow ignoring the prior sample limits for the posterior sample plot.

I still think this would make a nice feature, but there is a trade-off here between keeping the syntax simple and adding this feature.

---

<div class="post-metadata">

**Author:** ![olaf.klein](https://uqworld.org/user_avatar/uqworld.org/olaf.klein/32/468_2.png) [@olaf.klein](https://uqworld.org/u/olaf.klein)\
**Post date:** [May 6, 2022, 11:39am UTC](https://uqworld.org/t/uq-display-uq-inversion-determine-limits-for-scatter-plots-for-posteriori-samples-from-the-posteriori-samples-instead-of-using-prior-samples-at-least-if-there-no-prior-samples/1141/5 "2022-05-06T11:39:11Z")

</div>

Dear @paulremo ,

thanks for your fast replay and for your all support in the past.
