Skip to content

Linewidth(s) keywords not working with quiver #8630

Closed

Description

@Silmathoron

Cannot set different arrow sizes using quiver

This seems to be a regression in the behaviour of the quiver function

According to this SO post, quiver used to accept a linewidths array argument to set the arrow sizes; however, this is no longer true with 2.02 on Py2/3K.
The linewidth item pops 5 times in quiver.py though.

Code for reproduction
From the SO post, but the code (reported as working) does not work on my install.

import matplotlib.pyplot as plt
import numpy as np
sin = np.sin
cos = np.cos

# http://stackoverflow.com/questions/6370742/#6372413
xmax = 4.0
xmin = -xmax
D = 20
ymax = 4.0
ymin = -ymax
x = np.linspace(xmin, xmax, D)
y = np.linspace(ymin, ymax, D)
X, Y = np.meshgrid(x, y)
# plots the vector field for Y'=Y**3-3*Y-X
deg = np.arctan(Y ** 3 - 3 * Y - X)
widths = np.linspace(0, 2, X.size)
plt.quiver(X, Y, cos(deg), sin(deg), linewidths=widths)
plt.show()

Actual outcome

Output is the same as that of the initial SO post where the linewidths keyword is not set.

Matplotlib version

  • Operating System: Manjaro
  • Matplotlib Version: 2.02
  • Python Version: 2.7.13 & 3.6.1
  • Jupyter Version (if applicable): /
  • Other Libraries: numpy 1.12.1

Activity

  1. dstansby commented on May 16, 2017

    @dstansby
    Member

    Can confirm this on master, the problem bisects to #6904

  2. dstansby commented on May 16, 2017

    @dstansby
    Member

    As a workaround, it looks like you have to explicitly set the edgecolors kwarg to get what you want now, ie.:

    plt.quiver(X, Y, cos(deg), sin(deg), linewidths=widths, edgecolors='k')
  3. efiring commented on May 16, 2017

    @efiring
    Member

    All of this seems to reflect a misunderstanding of what quiver does and how to control the arrow properties. Quiver uses a patch collection, so each arrow has a face and an outline. Turning on the outline makes sense only when one wants to have an outline of one color and a face of another color. Otherwise, just rely on the face. The basic arrow dimension kwargs include:

    width : scalar, optional
        Shaft width in arrow units; default depends on choice of units,
        above, and number of vectors; a typical starting value is about
        0.005 times the width of the plot.
    headwidth : scalar, optional
        Head width as multiple of shaft width, default is 3
    headlength : scalar, optional
        Head length as multiple of shaft width, default is 5
    headaxislength : scalar, optional
        Head length at shaft intersection, default is 4.5
    minshaft : scalar, optional
        Length below which arrow scales, in units of head length. Do not
        set this to less than 1, or small arrows will look terrible!
        Default is 1
    minlength : scalar, optional
        Minimum length as a multiple of shaft width; if an arrow length
        is less than this, plot a dot (hexagon) of this diameter instead.
        Default is 1.
    

    So please use the width kwarg together with units; linewidths is only for controlling the outline thickness, when an outline of a different color is explicitly requested.

  4. Silmathoron commented on May 16, 2017

    @Silmathoron
    Author

    @dstansby this works great, thanks for the workaround! However, I still think this is a regression which should be fixed.

    @efiring there is no misunderstanding : I (as well as the other people from the SO post) need a non scalar argument to set different widths for each arrow. Therefore, I work with the only non-scalar argument at my disposal, which is linewidths.
    But if width can be modify to accept arrays, I totally agree that it would be better ;)

  5. efiring commented on May 16, 2017

    @efiring
    Member

    I really don't think this is a bug or regression, so I am closing it.

  6. Silmathoron commented on May 16, 2017

    @Silmathoron
    Author

    It is a feature, which, though you don't think it relevant, has been, and is still useful to users...
    Couldn't this feature of an array widths/linewidths at least be put on the wishlist, then?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions