You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
ENH: functional boxplot - highest density region #3864
Based on a quick look
We allow users to specify a ax or figure where the plots are added. You can look at other plot functions to see how that works and the helper function that we use.
Two possibilities if there are several plots that share common computation:
use subplots or plot grid to combine several plots into one figure and return that figure
return an instance of a results class: If there is a lot of common computation, then it might be useful for users to access those intermediate results directly. Using a results class would have the advantage of separating the underlying computation from plot methods, especially if there are several plots.
@josef-pkt Correct me if I am wrong, the second option means creating a class that:
Fit the data,
Provide a plot method.
If this is the case, I have done such class so It won't be an issue to adapt it now I have this code.
The first option will not be pretty I am afraid. But the question might be, do we really need the extra plots? Because among the following [hdr_boxplot.pdf], we are interested in the last one. So we can imagine returning ax for this main plot and some extras to do the other plots. In fboxplot, ax is returned along with other infos.
We have several "patterns" that depend on the focus of the functions/classes/methods, what is of main interest to the user and what is additional information that some users might want to have access to.
I don't know yet what is the case here.
If you think the focus is on the last plot, then following the fboxplot example would work. If there is more information or there are more plots and supporting methods, then using a class would be more appropriate, (e.g.
(i) A function could return a results instance;
(ii) a single class could handle everything and use attributes; or
(iii) class that does the computation returns a class that provides the plot methods.)
I have committed a version that works as fboxplot. In the first place, I considered a function to be consistent with the other functional plot functions. So if what I have done so far seems enough, I can do the PR with that (after test fixed, and doc obviously). Otherwise I can port the changes I have made here to the class version which will enable to define several plot methods and have access to internal attributes. But this might be overkill.
Another point, this version is ok up to ncomp=3 but after that, we must use some global optimization methods to replace the search within a np.meshgrid. I also have this (actually with the class version).
Are your nested functions using variables from the main function scope? In general I prefer, and we usually put helper functions outside the functions. Besides possible reuse. it also makes debugging easier if problems show up. With leading underline those helper functions would be private.
I think the structure is fine with your plot function. I would prefer to use a dict or something else for the extra returns instead of returning a single tuple. That would make future changes in the extra returns backwards compatible when only the figure is used.
You could open a PR, and I try to go over the details later today.
Also, as I mentioned on the mailing list, I would like to eventually start a statsmodels.functional folder for functional data analysis. If you have or once we get more extensive computation besides the plotting support, then we could add classes there with the focus on estimation and data analysis with plots as supporting methods.
Activity
tupui commentedon Aug 18, 2017
@josef-pkt I am currently adapting the code to fit statsmodels. I created a branch here: https://github.com/tupui/HDR-Boxplot/tree/statsmodels
I replaced all dependencies and now it uses statsmodels methods. Still have to fix the tests and come up with a good way to return the plots.
josef-pkt commentedon Aug 18, 2017
Based on a quick look
We allow users to specify a
axor figure where the plots are added. You can look at other plot functions to see how that works and the helper function that we use.Two possibilities if there are several plots that share common computation:
tupui commentedon Aug 18, 2017
@josef-pkt Correct me if I am wrong, the second option means creating a class that:
If this is the case, I have done such class so It won't be an issue to adapt it now I have this code.
The first option will not be pretty I am afraid. But the question might be, do we really need the extra plots? Because among the following [hdr_boxplot.pdf], we are interested in the last one. So we can imagine returning
axfor this main plot and some extras to do the other plots. Infboxplot,axis returned along with other infos.josef-pkt commentedon Aug 18, 2017
We have several "patterns" that depend on the focus of the functions/classes/methods, what is of main interest to the user and what is additional information that some users might want to have access to.
I don't know yet what is the case here.
If you think the focus is on the last plot, then following the fboxplot example would work. If there is more information or there are more plots and supporting methods, then using a class would be more appropriate, (e.g.
(i) A function could return a results instance;
(ii) a single class could handle everything and use attributes; or
(iii) class that does the computation returns a class that provides the plot methods.)
tupui commentedon Aug 18, 2017
I have committed a version that works as
fboxplot. In the first place, I considered a function to be consistent with the other functional plot functions. So if what I have done so far seems enough, I can do the PR with that (after test fixed, and doc obviously). Otherwise I can port the changes I have made here to the class version which will enable to define several plot methods and have access to internal attributes. But this might be overkill.Another point, this version is ok up to ncomp=3 but after that, we must use some global optimization methods to replace the search within a
np.meshgrid. I also have this (actually with the class version).josef-pkt commentedon Aug 18, 2017
Are your nested functions using variables from the main function scope? In general I prefer, and we usually put helper functions outside the functions. Besides possible reuse. it also makes debugging easier if problems show up. With leading underline those helper functions would be private.
I think the structure is fine with your plot function. I would prefer to use a dict or something else for the extra returns instead of returning a single tuple. That would make future changes in the extra returns backwards compatible when only the figure is used.
You could open a PR, and I try to go over the details later today.
Also, as I mentioned on the mailing list, I would like to eventually start a statsmodels.functional folder for functional data analysis. If you have or once we get more extensive computation besides the plotting support, then we could add classes there with the focus on estimation and data analysis with plots as supporting methods.
tupui commentedon Aug 18, 2017
Currently yes but I can change that is sec.
I have committed the actual class in
hdr_class.pyso you can see.OK I open a PR then by adding for starting the function into
functional.py.rgommers commentedon Sep 22, 2017
This PR looks quite nice. I haven't used this type of functionality in a while, but +1 from me.
josef-pkt commentedon Oct 25, 2017
@tupui PR #3876 merged in rebased version in #4049