How to control the linewidth of the arviz.plot_ppc

Hi, everyone. I need to put the image output by arviz into the paper, but the paper strictly requires the line width to be 1pt.
However, I have tried many methods but cannot control the line width of the posterior prediction check graph output by arviz.plot_ppc. I checked the manual and there is no relevant control parameter.
thank you very much.

Hi,

plot_ppc returns the axis so you can use it to modify the line widths by hand (selecting based on color):


import pymc as pm
import numpy as np
import arviz as az

data = np.random.normal(0, 1, size=(100,))

with pm.Model() as m:
  
  mu = pm.Normal("mu", 1)
  sd = pm.Exponential("sd", 1)
  
  obs = pm.Normal("obs", mu, sd, observed=data)
  
  idata = pm.sample(tune=100, draws=1000, chains=4)
  
with m:
  pm.sample_posterior_predictive(idata, extend_inferencedata=True)
  
ax = az.plot_ppc(idata, num_pp_samples=100)
ax.get_figure().savefig("before.png")

for line in ax.lines:
  
  #C0 blue: individual posterior predictive samples
  #C1 orange: mean posterior predictive
  #k black: obs
  
  line_color = line.get_color()
  
  if line_color in ["C1","k"]:
    line.set_linewidth(1.)
    
ax.get_figure().savefig("after.png")
1 Like

Thank you very much. Based on your code, I have solved the problem.
My problem was not realizing that az.plot_ppc had thousands of sampled lines.
Thank you again.