Skip to content

Commit

Permalink
Merge pull request #561 from SasView/pr-labels-on-weights-plot
Browse files Browse the repository at this point in the history
Put labels on weights plot for sasmodels compare app
  • Loading branch information
Wojciech Potrzebowski committed May 23, 2023
2 parents 7ceea84 + f8664db commit 460b026
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 9 deletions.
2 changes: 1 addition & 1 deletion sasmodels/compare.py
Original file line number Diff line number Diff line change
Expand Up @@ -812,7 +812,7 @@ def compare(opts, limits=None, maxdim=None):
if have_comp:
plot_profile(comp._kernel.info, label='comp', **comp_pars)
pylab.legend()
if opts['plot']:
if opts['plot'] or opts['show_weights'] or opts['show_profile']:
import matplotlib.pyplot as plt
plt.show()
return limits
Expand Down
22 changes: 14 additions & 8 deletions sasmodels/weights.py
Original file line number Diff line number Diff line change
Expand Up @@ -303,15 +303,21 @@ def plot_weights(model_info, mesh):
for each parameter, where (*dispersity*, *weights*) pairs are the
distributions to be plotted.
"""
import pylab

import matplotlib.pyplot as plt
if any(len(dispersity) > 1 for value, dispersity, weights in mesh):
labels = [p.name for p in model_info.parameters.call_parameters]
#pylab.interactive(True)
pylab.figure()
#plt.interactive(True)
plt.figure()
for (_, x, w), s in zip(mesh, labels):
if len(x) > 1:
pylab.plot(x, w, '-o', label=s)
pylab.grid(True)
pylab.legend()
#pylab.show()
# For plotting probability rather than weight scale by dx
#dx = np.hstack((x[1]-x[0], (x[2:] - x[:-2])/2, x[-1] - x[-2]))
#plt.plot(x, w/dx, '-o', label=s)
plt.plot(x, w, '-o', label=s)
plt.title("Distributions for polydisperse parameters")
plt.xlabel("parameter value")
#plt.ylabel("probability")
plt.ylabel("relative weight")
plt.grid(True)
plt.legend()
#plt.show()

0 comments on commit 460b026

Please sign in to comment.