Skip to content

Conversation

@AnderGray
Copy link
Contributor

@AnderGray AnderGray commented Oct 23, 2025

This PR adds the ability plot the following using plot recipes:

  • Distributions (both pdf and cdf)
  • IntervalVariables
  • P-boxes
  • A vector of UQInputs (plots it in a grid)
  • A vector of Intervals (the ecdf of a p-box)
  • A bivariate scatter of Intervals (ecdf of a bivariate p-box)

With plot recipes, various properties of the plots should be editable by the user as they would any standard plot with Plots.jl (i.e. color=:red, will make the plot red)

Eg, the following DEMO script (in demo/plotting):

using UncertaintyQuantification, Plots

X1 = RandomVariable(ProbabilityBox{Normal}(Dict( => Interval(-1, 2),  => 1)), :X1)
X2 = RandomVariable(ProbabilityBox{Normal}(Dict( => Interval(-1, 2),  => 2)), :X2)
X3 = IntervalVariable(-1, 2, :s)
h = RandomVariable(Normal(0.24, 0.01), :h) # height

plot(X1)    # p-box
plot(X1, color = "red") # red p-box
plot(X3)    # Interval
plot(h)     # distribution 

inputs = [X1, X2, X3, h]

plot(inputs)    # Everything together

samples = sample(inputs, 50)

plot(X1)
plot!(samples.X1)    # Interval ecdf of X1

plot(samples.X1[1], samples.X2[1])  # Plots 2D box

plot(samples.X1, samples.X2)        # Plots bivariate random sets of X1 and X2
plot_test1 plot_test_2 plot_test_3

@codecov-commenter
Copy link

codecov-commenter commented Oct 23, 2025

Codecov Report

❌ Patch coverage is 95.06173% with 8 lines in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
src/plotting/plot_recipes.jl 94.93% 8 Missing ⚠️

📢 Thoughts on this report? Let us know!

Copy link
Contributor

@FriesischScott FriesischScott left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Overall very nice plots!

I do have some things I'd prefer differently though:

  • by default I think the colour scheme should be the same as when plotting regularly, i.e. cycle through the default colours (blue, orange,...) with each extra plot added to a single figure. This way the colours are consistent with any other stuff the user might plot.
  • I don't really like the grey shaded area in all plots. For a PDF for example just the line should be sufficient. Maybe for the pbox and interval it makes sense though.
  • Instead of the xlabel I think the variable name should actually go in the plot label. Currently if I plot two pdfs in one figure the second one will override the name of the first. Without passing colours, they will also be the same colour.

Please also add a few plots in suitable areas of the documentation. For example where the inputs are introduced.


include("plotting/plot_recipes.jl")

include("util/fourier-transform.jl")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why did you move these util includes down here? It's probably not to important, but I think they can stay at the top.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You defined a lo(X::Real) and hi(X::Real) function but I don't think you use it anywhere.

Do you really need a function for the .lb and .ub of the Interval? To get the bounds of a Vector{Interval} you could instead use getproperty.(X, :lb) and getproperty.(X, :ub).

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the review 👍 I think you're right

On the last one, I do find it convenient to have hi and lo functions for intervals and reals. It lets you ask for bounds on random sample of inputs, without knowing which elements are interval or real.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In that case, keep them 👍

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add plot recipes

4 participants