Skip to content
Advertisement

Function plotting with matplotlib

I am trying to model an equation that depends on T and parameters xi, mu, sig.

I have inferred parameters and spread(standard deviation) of those parameters for different durations (1h, 3h, etc). In the example code the parameters are for 1h duration.

I need to create a forloop to create a cloud of zp with the array of xi, mu and sig. The different values T can take are [2, 5, 25, 50, 75, 100]

I also want to show error bars or uncertainty with the standard deviation in line 2. I used Metropolis Hastings Algorithm for exploring the parametric space with 15000 iterations in 3 chains

JavaScript

Advertisement

Answer

So, you have the (15000,3) matrix accepted, where xi=accepted[:,0], mu=accepted[:,1] and sig=accepted[:,2].

I will generate some sample data for xi, mu and sig, just to show you the results of plotting.

JavaScript

You defined T as

JavaScript

Now we take mean and standard deviation of parameters

JavaScript

and define a function zp

JavaScript

We can define a DataFrame with all results

JavaScript

Now we compute zp with mean +/- std of parameters

JavaScript

and we can finally plot the 15000 lines and mean+/-std

JavaScript

enter image description here


You could also choose a faster solution with seaborn.

First, melt the DataFrame

JavaScript

then plot with relplot and choose the wanted confidence interval (here is 99%, could be also 'sd')

JavaScript

enter image description here

User contributions licensed under: CC BY-SA
5 People found this is helpful
Advertisement