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

Fix 1D quiver when transforming projections #674

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 2 additions & 2 deletions lib/cartopy/mpl/geoaxes.py
Expand Up @@ -1364,7 +1364,7 @@ def pcolor(self, *args, **kwargs):

def quiver(self, x, y, u, v, *args, **kwargs):
"""
Plot a 2-D field of arrows.
Plot a field of arrows.

Extra Kwargs:

Expand Down Expand Up @@ -1428,7 +1428,7 @@ def quiver(self, x, y, u, v, *args, **kwargs):
elif t != self.projection:
# Transform the vectors if the projection is not the same as the
# data transform.
if x.ndim == 1 and y.ndim == 1:
if (x.ndim == 1 and y.ndim == 1) and (x.shape != u.shape):
x, y = np.meshgrid(x, y)
u, v = self.projection.transform_vectors(t, x, y, u, v)
return matplotlib.axes.Axes.quiver(self, x, y, u, v, *args, **kwargs)
Expand Down
63 changes: 63 additions & 0 deletions lib/cartopy/tests/test_quiver_shape.py
@@ -0,0 +1,63 @@
# (C) British Crown Copyright 2015, Met Office
#
# This file is part of cartopy.
#
# cartopy is free software: you can redistribute it and/or modify it under
# the terms of the GNU Lesser General Public License as published by the
# Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# cartopy is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Lesser General Public License for more details.
#
# You should have received a copy of the GNU Lesser General Public License
# along with cartopy. If not, see <http://www.gnu.org/licenses/>.

from __future__ import (absolute_import, division, print_function)

from nose.tools import raises

import numpy as np
import matplotlib.pyplot as plt

import cartopy.crs as ccrs


class TestQuiverShapes(object):

@classmethod
def setup_class(cls):
cls.x = np.arange(-60, 42.5, 2.5)
cls.y = np.arange(30, 72.5, 2.5)
cls.x2d, cls.y2d = np.meshgrid(cls.x, cls.y)
cls.u = np.cos(np.deg2rad(cls.y2d))
cls.v = np.cos(2. * np.deg2rad(cls.x2d))
cls.rp = ccrs.RotatedPole(pole_longitude=177.5, pole_latitude=37.5)
cls.pc = ccrs.PlateCarree()

def test_quiver_transform_xyuv_1d(self):
fig, ax = plt.subplots(subplot_kw=dict(projection=self.pc))
ax.quiver(self.x2d.ravel(), self.y2d.ravel(),
self.u.ravel(), self.v.ravel(), transform=self.rp)

def test_quiver_transform_xyuv_2d(self):
fig, ax = plt.subplots(subplot_kw=dict(projection=self.pc))
ax.quiver(self.x2d, self.y2d, self.u, self.v, transform=self.rp)

def test_quiver_transform_xy_1d_uv_2d(self):
fig, ax = plt.subplots(subplot_kw=dict(projection=self.pc))
ax.quiver(self.x, self.y, self.u, self.v, transform=self.rp)

@raises(ValueError)
def test_quiver_transform_xy_2d_uv_1d(self):
fig, ax = plt.subplots(subplot_kw=dict(projection=self.pc))
ax.quiver(self.x2d, self.y2d,
self.u.ravel(), self.v.ravel(), transform=self.rp)

@raises(ValueError)
def test_quiver_transform_inconsistent_shape(self):
fig, ax = plt.subplots(subplot_kw=dict(projection=self.pc))
ax.quiver(self.x, self.y,
self.u.ravel(), self.v.ravel(), transform=self.rp)