Axes labels for ModelResult.plot()

305 views
Skip to first unread message

Ian Hunt-Isaak

unread,
Nov 30, 2015, 2:20:05 AM11/30/15
to lmfit-py
Hello,

I'm fairly new to lmfit and loving it and have a suggestion for an improvement that I didn't post on github because I'm not sure if a feature request should count as an issue. 

The current ModelResult.plot method doesn't allow for descriptive naming of the axes or titles as can be seen here:



This plot would be much enhanced by xlabel=angle, ylabel=Intensity.  These labels are set in the code here-fit and here-residuals and I haven't found a way to change the labels after calling plot(). The current labels of x,y,and residuals are perfectly fine as defaults but it would be nice if plot accepted a labels_kws dict as an argument that would set the axis labels and also plot titles. This should be fairly easy to implement and I'm happy to submit a pull request if this is deemed worthwhile but wasn't sure I should go ahead and do that without asking first. 

So actual questions are:
1. Does a feature request belong here or on the issue tracker?
2. Is there an easy method of changing the axes labels after the figure has been created that I haven't figured out?
3. Assuming no to question 2: Is custom axis naming for ModelResult.plot() something that should be implemented?

Cheers,
Ian

Matt Newville

unread,
Nov 30, 2015, 8:35:30 AM11/30/15
to Ian Hunt-Isaak, lmfit-py
Hi Ian,

On Mon, Nov 30, 2015 at 1:20 AM, Ian Hunt-Isaak <ianhun...@gmail.com> wrote:
Hello,

I'm fairly new to lmfit and loving it and have a suggestion for an improvement that I didn't post on github because I'm not sure if a feature request should count as an issue. 


Thanks for using the mailing list.   I think requests for feature enhancements are fine for Issues, but (as you will see), it might be easiest to do this without changing lmfit.
 
The current ModelResult.plot method doesn't allow for descriptive naming of the axes or titles as can be seen here:



This plot would be much enhanced by xlabel=angle, ylabel=Intensity.  These labels are set in the code here-fit and here-residuals and I haven't found a way to change the labels after calling plot(). The current labels of x,y,and residuals are perfectly fine as defaults but it would be nice if plot accepted a labels_kws dict as an argument that would set the axis labels and also plot titles. This should be fairly easy to implement and I'm happy to submit a pull request if this is deemed worthwhile but wasn't sure I should go ahead and do that without asking first.
 

So actual questions are:
1. Does a feature request belong here or on the issue tracker?

It could...
 
2. Is there an easy method of changing the axes labels after the figure has been created that I haven't figured out?

Yes.   ModelResult.plot_fit() returns the axes, and your links above show how the labels are set.  So, you could just do

     my_model = Model(....)
     result = my_model.fit(...)
     ax  = result.plot_fit(...)
     ax.set_xlabel(' New X Axis')
     ax.set_ylabel(' New Y Axis')


The ModelResult.plot() method returns a 'figure', but you can use its get_axes() method to get a sequence of the two 'axes', and then proceed as above.

3. Assuming no to question 2: Is custom axis naming for ModelResult.plot() something that should be implemented?


Could be.  I don't have a strong opinion.  Anyone else have an opinion?

--Matt

Ian Hunt-Isaak

unread,
Nov 30, 2015, 12:55:28 PM11/30/15
to lmfit-py, ianhun...@gmail.com, newv...@cars.uchicago.edu
Thanks very much, it is indeed very easy to do what I want using get_axes(). 

However I'd like to suggest that it would be more intuitive to be able to do:
result.plot(fig_kws={'figsize':(10,10)},labels={'ylabel':'Intensity','xlabel':'Angle (Deg)','title':'Michel Model'})
Instead of
axes = result.plot(fig_kws={'figsize':(10,10)}).get_axes()
axes[1].set_ylabel('Intensity')
axes[1].set_xlabel('Angle (Deg)')
axes[1].set_title('')
axes[0].set_title('Michel Model')

Best,
Ian

Matt Newville

unread,
Nov 30, 2015, 5:29:45 PM11/30/15
to Ian Hunt-Isaak, lmfit-py
Hi Ian,


On Mon, Nov 30, 2015 at 11:55 AM, Ian Hunt-Isaak <ianhun...@gmail.com> wrote:
Thanks very much, it is indeed very easy to do what I want using get_axes(). 

However I'd like to suggest that it would be more intuitive to be able to do:
result.plot(fig_kws={'figsize':(10,10)},labels={'ylabel':'Intensity','xlabel':'Angle (Deg)','title':'Michel Model'})
Instead of
axes = result.plot(fig_kws={'figsize':(10,10)}).get_axes()
axes[1].set_ylabel('Intensity')
axes[1].set_xlabel('Angle (Deg)')
axes[1].set_title('')
axes[0].set_title('Michel Model')

Best,
Ian


I think the main point would be that once could easily get carried away with plotting options for what is really meant to be a quick, default view of a fit.   So, yes allowing custom labels is a fine idea.  And maybe colors, and line widths, and background colors. And z order.  And fonts.  And the location of the legend.  You get the idea...  there are a lot of options available. 

When we introduced these plotting functions, the discussion (see https://groups.google.com/forum/#!topic/lmfit-py/j5FG2fgWOoM) more or less concluded that returning the matplotlib figure / axes was the right way to allow customization.   Like, the code to do the plots is not really that much code and blessedly more documentation than code.  I think we want to keep it that way, and not have plotting become the dominant part of a Model Result.  Other libraries already do plotting very well.

So, I'm not 100% against this idea, and could be persuaded, but I'm not sure this is needed.

Any one else have an opinion?

--Matt Newville
Reply all
Reply to author
Forward
0 new messages