How to add coastlines to a UXARRAY plot #861
-
Apologies if this is duplicating another discussion (I looked but didn't see one quite like what I was looking for), but I am just wondering how to include coastlines in uxarray plots. In some maps I've seen it's pretty obvious where the continents are simply from looking at the contours, but I have some noisier data that's unfortunately not so clear. I can plot a map, but without the coastlines it's hard to interpret. Is there a simple fix for this? Currently I'm using the command:
|
Beta Was this translation helpful? Give feedback.
Replies: 5 comments 12 replies
-
Hi @bstephens82 Since our plotting API is written using GeoViews, you can add any feature you'd like by using the following syntax import geoviews.feature as gf
projection = projection=ccrs.PlateCarree()
uxds['ug_mean_lev'][0,:].plot(title="ug_mean_lev", cmap='cubehelix_r', projection=ccrs.PlateCarree()) * gf.coastline(projection=projection) You can see an example of this in our MPAS Visualization Example. I would note that only our Point plotting currently supports other projections as of right now using our direct API. We are working on getting this in soon. If you are interested in a more classic Matplotlib implementation using Cartopy, we have recently added a new User Guide section describing how to achieve this. This implementation does support any projection (even for Polygon plotting). Using Matplotlib, it would look something like: import matplotlib.pyplot as plt
import cartopy.crs as ccrs
import cartopy.feature as cfeature
projection=ccrs.PlateCarree()
# create a Matplotlib PolyCollection
pc = uxds['ug_mean_lev'][0,:].to_polycollection(projection=projection)
pc.set_antialiased(False)
pc.set_cmap("cubehelix_r")
fig, ax = plt.subplots(
1,
1,
figsize=(10, 5),
facecolor="w",
constrained_layout=True,
subplot_kw=dict(projection=projection),
)
# add geographic features
ax.add_feature(cfeature.COASTLINE)
ax.add_feature(cfeature.BORDERS)
ax.add_collection(pc)
ax.set_global()
plt.title("ug_mean_lev")
|
Beta Was this translation helpful? Give feedback.
-
Thanks very much @philipc2! I got your first suggestion working. Regarding your second suggestion, does that require a recent update to uxarray or something? I get error messages when I try to run it, like it complains that "projection" is not a recognized argument for |
Beta Was this translation helpful? Give feedback.
-
Hi @philipc2 thanks again for your help so far, I've figured out those issues I think. I had one other question...what if I have a variable on an unstructured grid that's not in the |
Beta Was this translation helpful? Give feedback.
-
Hi @philipc2, I have another small question about something that doesn't seem to be working. I would like to use the
and this doesn't give any complaints by itself, but when I try to plot the result of something like this, it gives a weird complaint about not recognizing the "title" I've put into the
If I comment out the line with
Any ideas? Does |
Beta Was this translation helpful? Give feedback.
-
Hi @philipc2, is there an easy way to get my uxarray plots on a logarithmic color scale? I was able to figure out how to set limits to the color scale but not how to get it on a log scale. Thanks! Here's a piece of code as an example:
|
Beta Was this translation helpful? Give feedback.
Hi @bstephens82
Since our plotting API is written using GeoViews, you can add any feature you'd like by using the following syntax
You can see an example of this in our MPAS Visualization Example. I would note that only our Point plotting currently supports other projections as of right now using our direct API. We are working on getting this in soon.
If you are interested in a more classic Matplotlib implementation using Cartopy, we have recently added a new User Guide section …