[TL;DR: is it possible to control the length of the dashes in dashed contours, if so how?]
I’d like to be able to control the length of dashes for dashed contours. My motivation is that I’m making a contour plot that uses dashes for the negative contours, and the plot needs to be a specific (small) size for the particular journal, so the small size of the plot makes the dashes look rather long and is a problem for some tight contours.
I have tried using some a dashes-style argument for the linestyles keyword of contour but I can’t get it to work (although I appreciate it is not documented as something one can do). For example I tried:
import matplotlib.pyplot as plt
import numpy as np
x = y = np.linspace(-np.pi, np.pi, 100)
X, Y = np.meshgrid(x, y)
Z = np.sin(X) * np.cos(Y)
plt.contour(x, y, Z, linestyles=[(3, 3)])
plt.show()
This fails at the point where I show (or save, doesn’t matter which backend) the plot with a PyCXX error:
TypeError: PyCXX: Error creating object of type N2Py7SeqBaseINS_6ObjectEEE from 3
I’ve fiddled with several other styles of argument and all fail in a similar way.
What I’d like to know is: is it possible to control the dash length of dashed contours at all? It seems like it should be as one can do this with lines easy enough. I looked through the code, and a dashes-style argument seems to get passed through the stack correctly, but fails when the Collection is drawn. It would be a really nice feature if this could be implemented in matplotlib.
[TL;DR: is it possible to control the length of the dashes in dashed
contours, if so how?]
I'd like to be able to control the length of dashes for dashed contours.
My motivation is that I'm making a contour plot that uses dashes for the
negative contours, and the plot needs to be a specific (small) size for
the particular journal, so the small size of the plot makes the dashes
look rather long and is a problem for some tight contours.
I have tried using some a dashes-style argument for the linestyles
keyword of contour but I can't get it to work (although I appreciate it
is not documented as something one can do). For example I tried:
import matplotlib.pyplot as plt
import numpy as np
x = y = np.linspace(-np.pi, np.pi, 100)
X, Y = np.meshgrid(x, y)
Z = np.sin(X) * np.cos(Y)
plt.contour(x, y, Z, linestyles=[(3, 3)])
plt.show()
This fails at the point where I show (or save, doesn't matter which
backend) the plot with a PyCXX error:
TypeError: PyCXX: Error creating object of type
N2Py7SeqBaseINS_6ObjectEEE from 3
I've fiddled with several other styles of argument and all fail in a
similar way.
There seems to be a nasty tangle of bugs and obsolete documentation here. It should be perfectly simple and straightforward, but it isn't.
Eric
···
On 2013/01/22 11:50 PM, Andrew Dawson wrote:
What I'd like to know is: is it possible to control the dash length of
dashed contours at all? It seems like it should be as one can do this
with lines easy enough. I looked through the code, and a dashes-style
argument seems to get passed through the stack correctly, but fails when
the Collection is drawn. It would be a really nice feature if this could
be implemented in matplotlib.
Thanks,
Andrew
------------------------------------------------------------------------------
Master Visual Studio, SharePoint, SQL, ASP.NET, C# 2012, HTML5, CSS,
MVC, Windows 8 Apps, JavaScript and much more. Keep your skills current
with LearnDevNow - 3,200 step-by-step video tutorials by Microsoft
MVPs and experts. ON SALE this month only -- learn more at: http://p.sf.net/sfu/learnnow-d2d