GithubHelp home page GithubHelp logo

Comments (10)

rubencalje avatar rubencalje commented on June 1, 2024 1

Hey @rubencalje, what if we use a special setting for extent that will do what you want. Maybe if the extent is an empty list, for example, we could not change the axes limits in the plot routine? Would that solve your use case?

That would help.

One last try: a cleaner way would be to check if the axis limits have not been set, with the line ax.get_autoscale_on(), and only set the axes limits to the model extent when this is True.

from flopy.

langevin-usgs avatar langevin-usgs commented on June 1, 2024

Hey Ruben, I think the easy way to handle this is to make the changes to ax later on. Maybe something like this?

f, ax = plt.subplots()
pmv = flopy.plot.PlotMapView(modelgrid=modelgrid, ax=ax)
pmv.plot_grid()

ax.axis('scaled')
ax.axis([500, 800, 200, 400])

Note that you can pass ax into PlotMapView. Would that work?

from flopy.

rubencalje avatar rubencalje commented on June 1, 2024

Hi @langevin-usgs, thank you for the reply.

You are right, I forgot to supply the ax in PlotMapView in my example code.

In my workflow (and possibly of other people as well) I generate a figure with a specified extent to plot a lot of stuff, and also some properties of the model. Then it is useful that the axis limits are not changed by PlotMapView, just like GeoPandas does not change fixed axes limits when a GeoDataFrame is plotted.

This is not a mayor issue, as it is easy to work around, as you show. But it may be a small improvement to the plotting features of flopy.

from flopy.

jlarsen-usgs avatar jlarsen-usgs commented on June 1, 2024

Hi @rubencalje,

PlotMapView has an exent parameter that can be used to set the plotting extent. The current behaviour, if the extent parameter is not passed in by the user, is to calculate the modelgrid extent (based on coordinates and rotation) and set the axis limits based on that. The reason we explicitly do this is that matplotlib buffers around the data when no axis limits are set.

Here's an example of using the extent parameter:

f, ax = plt.subplots()
ax.axis('scaled')
pmv = flopy.plot.PlotMapView(modelgrid=modelgrid, ax=ax, extent=[500, 800, 200, 400])
pmv.plot_grid()

from flopy.

rubencalje avatar rubencalje commented on June 1, 2024

Hi @jlarsen-usgs,

Thanks for your tip on adding the extent parameter to PlotMapView. That is also a good workaround.

My point was that it is possible to check if the user has already set the axes limits, so PlotMapView does not change the axes limits if they are fixed already. I believe you do not think this is worth a change, so let's keep it the way it is now.

Thank you for your time. I will close this issue now.

from flopy.

langevin-usgs avatar langevin-usgs commented on June 1, 2024

Hey @rubencalje, what if we use a special setting for extent that will do what you want. Maybe if the extent is an empty list, for example, we could not change the axes limits in the plot routine? Would that solve your use case?

from flopy.

jlarsen-usgs avatar jlarsen-usgs commented on June 1, 2024

@rubencalje

I like that suggestion and didn't realize that matplotlib axes objects have a method to check whether they have been autoscaled or previously scaled by the user. I'll put together an update for the plotting routines to incorporate this as a check before we rescale the axes limits.

from flopy.

rubencalje avatar rubencalje commented on June 1, 2024

That is great!

If you have little time I can also add a small pull request as well, with some minor changes that should work. I first thought the code could be much simpler, by only adjusting the axes limits in the __init__ method of PLotMapView, if necessary. But in all the plot-methods in PlotMapView it is possible to add a (different) axes as an argument, which makes it slightly more difficult.

I changed

if extent is not None:
    self._extent = extent
else:
    self._extent = None

by

if extent is None:
    if self.ax.get_autoscale_on():
        self._extent = self.mg.extent
    else:
        self._extent = None
else:
    self._extent = extent

and

@property
def extent(self):
    if self._extent is None:
        self._extent = self.mg.extent
    return self._extent

by

@property
def extent(self):
    if self._extent is None:
        return self.ax.axis()
    else:
        return self._extent

Then, in each of the plot methods I replaced:

ax.set_xlim(self.extent[0], self.extent[1])
ax.set_ylim(self.extent[2], self.extent[3])

by

if ax.get_autoscale_on():
    ax.axis(self.extent)

from flopy.

jlarsen-usgs avatar jlarsen-usgs commented on June 1, 2024

@rubencalje

I drafted up some code last night that I think will solve the issue. Instead of setting axes limits directly in each plotting method, we can route the limit settings through a generalized function like this:

    def _set_axes_limits(self, ax):
        """
        Internal method to set axes limits

        Parameters
        ----------
        ax : matplotlib.pyplot axis
            The plot axis

        Returns
        -------
        ax : matplotlib.pyplot axis object

        """
        if ax.get_autoscale_on():
            ax.set_xlim(self.extent[0], self.extent[1])
            ax.set_ylim(self.extent[2], self.extent[3])
        return ax

I still need to put some tests together to make sure it's working as expected, but I think this issue should be resolved fairly soon.

from flopy.

rubencalje avatar rubencalje commented on June 1, 2024

Great! Thank you.

from flopy.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.