Plot space that crosses 180 degrees #5450
-
Below is my attempt to plot SST in the Pacific Ocean between 5S and 5N, and between 160W and 80E. If someone could quickly explain to me how to change the longitude breakingpoint of the plot, I'd be much appreciative. I cannot come up with useful search words. Line 4 in 2a9e131 |
Beta Was this translation helpful? Give feedback.
Replies: 13 comments
-
@SciTools/peloton There are a number of potential causes for the graph not working as expected, to pinpoint the problem we would need to recreate the cube or have access to the data. Could you upload a single timestep of the cube? Thanks for raising this! |
Beta Was this translation helpful? Give feedback.
-
Thank you! |
Beta Was this translation helpful? Give feedback.
-
Can replicate the issue in the latest iris version.
If I plot the data manually using a PlateCarree projection I get a contiguous plot as expected
And the cube doesn't have any coord_system attached so it should be using PlateCarree
That's my initial ideas, any other thoughts on the cause of this issue? |
Beta Was this translation helpful? Give feedback.
-
Update: Any further thoughts in the meantime on how to deal with this issue @HGWright? |
Beta Was this translation helpful? Give feedback.
-
I think you need to set up your GeoAxes with a chosen central longitude (default is 0). import matplotlib.pyplot as plt
import cartopy.crs as ccrs
import iris
import iris.quickplot as qplt
cube = iris.load_cube("pacific_example.nc")
ax = plt.subplot(111, projection=ccrs.PlateCarree(central_longitude=210))
qplt.pcolormesh(cube, axes=ax)
plt.show() Arguable Iris could/should be more clever about choosing that for you automatically. |
Beta Was this translation helpful? Give feedback.
-
@SciTools/peloton Do you need further assistance @rebeccaherman1 with this issue? |
Beta Was this translation helpful? Give feedback.
-
Yes, @bjlittle, I think there's more to say. I am now avoiding the
This produces the following plot: However I have just realized that this results in relabeling 220E as 0, which means that I can no longer access the original longitude values for adding xticks to the plot, dramatically reducing the advantage of having the data in a cube. I'm working on a workaround for my present code now that I understand the problem, but I do not think this is a general sufficient approach. I agree with @rcomer that Iris should handle this automatically. |
Beta Was this translation helpful? Give feedback.
-
Maybe have a look at Cartopy's gridlines method for axis labels. import matplotlib.pyplot as plt
import cartopy.crs as ccrs
import numpy as np
import iris
import iris.quickplot as qplt
cube = iris.load_cube("pacific_example.nc")
ax = plt.axes(projection=ccrs.PlateCarree(central_longitude=210))
qplt.pcolormesh(cube, axes=ax)
ax.gridlines(draw_labels=True, linewidth=0, xlocs=[160, 180, -160, -140, -120, -100, -80])
plt.show() |
Beta Was this translation helpful? Give feedback.
-
Thank you, that is helpful. I must say that I find the available functions somewhat frustrating. I don't like that For another plot, I believe I need to use |
Beta Was this translation helpful? Give feedback.
-
I'm not sure about the For your EOF plot, the most likely explanation is that the circular property of your longitude coordinate is set to |
Beta Was this translation helpful? Give feedback.
-
Thanks for the explanation and the idea, @rcomer.
I think I wasn't expecting this because I had called
This is a property of the cube itself, right? It was a good idea, but I have checked, and the circular property of all components is set to 0. Incidentally, I wondered if this was potentially a reason why I was having trouble plotting the pacific_example, and if setting the coordinates to circular could stand in for setting the center of the plot. However, this does not help. However it does have an effect exactly like what I see in the EOF plot, but it doesn't seem to be the cause in the EOF case. Any ideas of other fields that could have the same effect? |
Beta Was this translation helpful? Give feedback.
-
@SciTools/peloton We are converting to a discussion as it seems to have moved on from the original question. |
Beta Was this translation helpful? Give feedback.
-
@SciTools/peloton There no longer seems to be any activity here, and a lot of the questions have been answered. So happy to close this. Please raise more issues/discussions when you need it. Thanks! |
Beta Was this translation helpful? Give feedback.
Maybe have a look at Cartopy's gridlines method for axis labels.
xticks
is a Matplotlib thing, and Matplotlib doesn't know anything about Cartopy's special transforms.