Comments (10)
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.
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.
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.
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.
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.
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.
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.
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.
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.
Great! Thank you.
from flopy.
Related Issues (20)
- VoronoiGrid creates "polygons" with less than 3 vertex pairs HOT 3
- bug: LGR utility CDIST is 2D, MF6 GWFGWF expects 3D HOT 2
- bug: `np.alltrue` will be deprecated in numpy 2.0 HOT 1
- bug: Budget from transport model listing file is not returned
- bug: gridintersect does not work for rotated vertex grids
- bug: Stack trace terminated abnormally. HOT 2
- bug: MF6 does not recognize the option name "BUDGETCSV" in LAK package written by FloPy (odd whitespace characters?) HOT 4
- bug: gwf.modeltime.steady_state inconsistent with input/output HOT 2
- bug: mf6 package name alters behavior with flopy HOT 1
- feat: support kper column in stress period recarray/dataframe input data
- bug: irch for rch and evt packages HOT 1
- bug: possible error detected in cvfd_utils cell centroids function shapefile_to_xcyc HOT 7
- bug: Grid intersect taking excessively long on simple voronoi grid HOT 6
- NumPy 2.0 compatibility HOT 2
- feat: list all simulation files
- feature: flopy.discretization.unstructuredgrid.intersect...but in 3D!? HOT 4
- bug: Plotting water table for Unstructured Grid HOT 3
- bug: check.py inconsistancies/errors
- feature: speed-up resample_to_grid HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from flopy.