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

quiver problems when angles is an array of values rather than 'uv' or 'xy' #6970

Closed
mlandriau opened this issue Aug 23, 2016 · 8 comments
Closed
Assignees
Milestone

Comments

@mlandriau
Copy link

I use the version of matplotlib that is included in the following distribution:
Python 3.5.2 |Anaconda 4.1.1 (x86_64)| (default, Jul 2 2016, 17:52:12)
IPython 4.2.0 -- An enhanced Interactive Python.

quiver produces the following warnings when called with angles=array :

/Users/mlandriau/anaconda/lib/python3.5/site-packages/matplotlib/quiver.py:609: FutureWarning: elementwise comparison failed; returning scalar instead, but in the future will perform elementwise comparison
if self.angles == 'xy' and self.scale_units == 'xy':
/Users/mlandriau/anaconda/lib/python3.5/site-packages/matplotlib/quiver.py:614: FutureWarning: elementwise comparison failed; returning scalar instead, but in the future will perform elementwise comparison
elif self.angles == 'xy' or self.scale_units == 'xy':
/Users/mlandriau/anaconda/lib/python3.5/site-packages/matplotlib/quiver.py:647: FutureWarning: elementwise comparison failed; returning scalar instead, but in the future will perform elementwise comparison
if self.angles == 'xy':
/Users/mlandriau/anaconda/lib/python3.5/site-packages/matplotlib/quiver.py:649: FutureWarning: elementwise comparison failed; returning scalar instead, but in the future will perform elementwise comparison
elif self.angles == 'uv':

It seems to produce the right answer, except quiverkey no longer works properly (the arrow is a filled half-circle instead of a line).

@tacaswell
Copy link
Member

What does matplotlib.__version__ return?

@tacaswell
Copy link
Member

and can you provide a minimal working example?

@tacaswell tacaswell added this to the 2.0.1 (next bug fix release) milestone Aug 24, 2016
@mlandriau
Copy link
Author

mlandriau commented Aug 24, 2016

The version of matplotlib is 1.5.1 and here is the code I used. The commented out line works fine, except it does not have the desired angles.

import numpy as np
import matplotlib.pyplot as plt
from matplotlib import rc
import matplotlib.ticker as ticker

def fmt(x, pos):
    a, b = '{:.2e}'.format(x).split('e')
    b = int(b)
    return r'${} \times 10^{{{}}}$'.format(a, b)

rc('font',**{'family':'sans-serif','sans-serif':['Helvetica']})
rc('text', usetex=True)

norm = 1.0
nmap = 1
n = int(ngrid)
for i in range(nmap):
    infile = 'map' + str(i+1) + '.dat'
    outfile = 'map' + str(i+1) + '.eps'
    data = np.genfromtxt(infile, names=['t', 'q', 'u'])
    t = np.reshape( data['t']  * norm, (n,n) )
    q = np.reshape( data['q'] * norm, (n,n) )
    u = np.reshape( data['u'] * norm, (n,n) )
    psi = (0.5 * np.arctan2(u,q)) * 180.0 / np.pi
    p = np.sqrt(q*q + u*u)
    pkey = 5.0 * np.mean
    pkeystr = fmt(pkey,0)
    fig = plt.figure()
    plt.axis('off')
    fig = plt.imshow(t, cmap='jet')
    plt.colorbar(format=ticker.FuncFormatter(fmt))
    x, y = np.meshgrid( range(n), range(n) )
    skip = ( slice(None, None, 4), slice(None, None, 4) )
    qv = plt.quiver(x[skip], y[skip], q[skip], u[skip], angles=psi[skip], headwidth=1, headlength=0.1, pivot='middle')
    #qv = plt.quiver(x[skip], y[skip], q[skip], u[skip], headwidth=1, headlength=0.1, pivot='middle')
    plt.quiverkey(qv, 0.4, 0.95, pkey, pkeystr, coordinates='figure', labelpos='E')
    plt.savefig(outfile, format='eps')
    plt.show()

@tacaswell
Copy link
Member

This is still not minimal example, I meant something more like

import matplotlib.pyplot as plt
import numpy as np

fig, ax = plt.subplots()

X, Y = np.meshgrid(np.arange(15), np.arange(10))
U = V = np.ones_like(X)
phi = (np.random.rand(15, 10) - .5) * 150
ax.quiver(X, Y, U, V, angles=phi)

which is sufficient to show the problem, is understandable, and (most importantly) is copy-paste-runnable.

@tacaswell
Copy link
Member

and I have a fix for this, just adding a test.

@tacaswell
Copy link
Member

@mlandriau Can you open a new issue for the quiverkey? It is not drawing a half-circle, it is drawing an arrow for each angle

import matplotlib.pyplot as plt
import numpy as np

fig, ax = plt.subplots()

X, Y = np.meshgrid(np.arange(5), np.arange(7))
U = V = np.ones_like(X)

phi = (np.random.rand(5, 7) - .5) * 150
q = ax.quiver(X, Y, U, V*.5, angles=phi, color='r', alpha=1)

qk = ax.quiverkey(q, 0.5, 0.92, 2, r'$2 \frac{m}{s}$',
                      labelpos='W',
                      fontproperties={'weight': 'bold'})

so

tacaswell added a commit to tacaswell/matplotlib that referenced this issue Aug 24, 2016
Do not try to compare a string to an array.

closes matplotlib#6970
@tacaswell tacaswell self-assigned this Aug 24, 2016
@mlandriau
Copy link
Author

Thanks, I've opened a new issue using the test code in your comment with one line added.

@jenshnielsen
Copy link
Member

For the record the new issue is #6972 this is closed by #6971

@QuLogic QuLogic modified the milestones: 2.0 (style change major release), 2.0.1 (next bug fix release) Aug 24, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants