-
Notifications
You must be signed in to change notification settings - Fork 190
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Refactoring of code: separation of concerns for ploting variograms #72
Comments
+1 for making the visualization more modular and for making matplotlib an optional dependency #63. Not sure if a separate class or function for plotting would be more appropriate (we should talk about the API in more detail). We might also consider deprecating (then removing after a while) the Generally, this is very much in line with refactoring proposed in #31 though addressing plotting instead of ND array handling... What do you think? |
On first glance a function seems sufficient if we just want to do a simple refactoring but a class could offer more freedom for adjustments, e.g. allowing the end user to add x-axis or y-axis titles, change the default colors etc. - things which might be of importance for publications. I agree that |
Well if the function returns I don't use the plotting functionality myself, so I don't have a very good understanding of all the use-cases (and on whether it should be a class or a function). @bsmurphy or @basaks might have a better idea.. |
Well, it is possible but stepping through all matplotlib elements can turn out quite nasty because you need some in-depth understanding of how to access and modify the elements. So for me |
I know matplotlib API can be not very straightforward, but still IMO, ax = plot_variogram(... )
ax.set_xlabel("some label") that would also support defining the figure externally, fix, ax = plt.subplots(111)
ax = plot_variogram(..., ax=ax)
ax.set_xlabel("some label") is preferable to plot_variogram(... , xlabel="some label") both because it means less maintenance (and potential issues) in PyKrige and because one can never know what the user might want to do with the plot (e.g. semi-log scales, some color styles etc) and we can't add all the posible matplotlib options as input arguments... |
The last negative example is a total no-go, my idea is to use a delegation pattern so that the user can plug in their personal plotting function if they want. The visualisation class can have methods like Here as a sketch: class Visualiser:
def after_plot_experimental_semivariogram(self, options):
pass
def initialise_plot_experimental_semivariogram(self, options):
fig = plt.figure()
ax = fig.add_subplot(111)
return axes
def plot_experimental_semivariogram(self, options):
self.initialise_plot_experimental_semivariogram(options)
# do the plotting
self.after_plot_experimental_semivariogram(axes, options)
plt.show() This way the user can adjust plotting easily: class MyVisualiser(Visualiser):
def after_plot_experimental_semivariogram(self, options):
plt.xlabel("heyho")
|
@1kastner Personally, I'm less in favour of creating custom classes for the public API in general, as opposed to some minimalistic functions as it takes more cognitive effort to understand how it works: i.e. in this case, instead of just applying what they know about matplotlib (that has very extensive documentation), users will have to understand how this custom mechanism works (and our documentation is not so great at the moment), which methods need to be subclassed etc. There is also a number of corner cases that's I'm not sure we really want to deal with: e.g. what if I make a plot in a jupyter notebook and don't need to call But anyway, you are very welcome to make a Pull Request, other people might have other perspectives on this as well. ) |
1. Yes, the proposed pattern is not used commonly in Python, at least not the small github projects available to public
2. When you check the pattern - subclassing is not necessarily needed, that would be just for convenience. It is not a must.
3. If you feel more comfortable, a function could do the work as well. That could be some drawing function which can be replaced by the user
|
Makes sense. In any case, you are welcome to submit a PR to make the
visualization better )
…On 23/08/17 09:14, 1kastner wrote:
1. Yes, the proposed pattern is not used commonly in Python, at least
not the small github projects available to public
2. When you check the pattern - subclassing is not necessarily needed,
that would be just for convenience. It is not a must.
3. If you feel more comfortable, a function could do the work as well.
That could be some drawing function which can be replaced by the user
Am 22. August 2017 15:54:20 MESZ schrieb Roman Yurchak
***@***.***>:
***@***.*** Personally, I'm less in favour of creating custom classes for
>the public API in general, as opposed to some minimalistic functions as
>it takes more cognitive effort to understand how it works: i.e. in this
>case, instead of just applying what they know about matplotlib (that
>has very extensive documentation), they will have to understand how
>this custom mechanism works (and our documentation is not so great at
>the moment), which methods need to be subclassed etc. There is also a
>number of corner cases that's I'm not sure we really want to deal with:
>e.g. what if I make a plot in a jupyter notebook and don't need to call
>`plt.show()`, what if I have some large dataset and I want to subsample
>or do parallel processing of it before variogram visualization, etc.
>Also once it is added to the public API, it will need to be maintained
>for the foreseeable future (e.g. can't just rename
>`initialise_plot_experimental_semivariogram` method if we find a better
>name for it, as it will break users code). So the simpler it is, the
>simpler it would be to maintain and use, and in particular, I can't
>think of any widely used Python package that would require subclassing
>to make a plot..
>
>But anyway, you are very welcome to make a Pull Request, other people
>might have other perspectives on this as well. )
>
>--
>You are receiving this because you were mentioned.
>Reply to this email directly or view it on GitHub:
>#72 (comment)
--
Diese Nachricht wurde von meinem Android-Mobiltelefon mit K-9 Mail
gesendet.
—
You are receiving this because you commented.
Reply to this email directly, view it on GitHub
<#72 (comment)>,
or mute the thread
<https://github.com/notifications/unsubscribe-auth/AAmgmH7G9JKmU737DcC8c_n5sAgbzHymks5sa8NhgaJpZM4O7PJy>.
|
I want to display an experimental variogram even before deciding which kriging method I want to use. Now what I can do is using
pykrige.ok.OrdinaryKriging.display_variogram_model
orpykrige.uk.UniversalKriging.display_variogram_model
. Two issues come to my mind:My idea is to extract a visualizer as a class on its own that can does the plotting. That visualizer is used by any call of display_variogram_model and keeps the matplotlib code at one place. If somebody does not have matplotlib installed, it only needs to be handled in the visualizer class. Further it can give the freedom to plot only the experimental variogram as well.
The text was updated successfully, but these errors were encountered: