Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

pcolormesh / _draw_2d_from_bounds doesn't handle time coordinates #3347

Closed
rcomer opened this issue Jul 4, 2019 · 1 comment
Closed

pcolormesh / _draw_2d_from_bounds doesn't handle time coordinates #3347

rcomer opened this issue Jul 4, 2019 · 1 comment

Comments

@rcomer
Copy link
Member

rcomer commented Jul 4, 2019

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()

contourf produces this:
tcoord_contour

For the pcolormesh plot, matplotlib thows an error about non datetime values. Without the set_major_formatter call, we get this:
pcolormesh_eg

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.

@rcomer rcomer changed the title polormesh / _draw_2d_from_bounds doesn't handle time coordinates pcolormesh / _draw_2d_from_bounds doesn't handle time coordinates Jul 4, 2019
@rcomer
Copy link
Member Author

rcomer commented Sep 14, 2020

Fixed by #3762 😎 .

@rcomer rcomer closed this as completed Sep 14, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant