-
Notifications
You must be signed in to change notification settings - Fork 301
Closed
Labels
Description
This was raised via Met Office Yammer. Given a 2d cube with a time dimension, pcolormesh does not recognise the time coordinate as such. Example:
import iris
import iris.plot as iplt
import numpy as np
import matplotlib.pyplot as plt
import matplotlib.dates as mdates
time_coord = iris.coords.DimCoord(range(12), standard_name='time',
units='days since 2019-06-01')
height_coord = iris.coords.DimCoord(range(5), standard_name='height', units='m')
cube = iris.cube.Cube(np.arange(12) + np.arange(5)[:, np.newaxis])
for dim, coord in enumerate([height_coord, time_coord]):
cube.add_dim_coord(coord, dim)
iplt.contourf(cube)
plt.gca().xaxis.set_major_formatter(mdates.DateFormatter('%d %b'))
plt.show()
iplt.pcolormesh(cube)
plt.gca().xaxis.set_major_formatter(mdates.DateFormatter('%d %b'))
plt.show()For the pcolormesh plot, matplotlib thows an error about non datetime values. Without the set_major_formatter call, we get this:

contourf uses _draw_2d_from_points which has specific handling for time coordinates. pcolormesh uses _draw_2d_from_bounds, which doesn't have this handling (as far as I can see). So possibly we just need to add that if loop to make it consistent (I haven't tried).
There seems to be a fair bit of overlap between the code of _draw_2d_from_points and _draw_2d_from_bounds, so I wonder if it's worth doing some rationalisation while addressing this.
Reactions are currently unavailable
