Hello,
I have attached a patch that addresses the following:
plot accepts the linestyles arguments '-','--','-.',':' [+ some more]
and the Collection class accepts the
linestyle arguments 'solid','dashed','dashdot','dotted'.
This patch allows to use both notations. A test script is attached too.
So its possible to use
plot(x,y, linestyle='--') # old (preferred) style
plot(x,y, linestyle='dashed') # now also possible
and also
contour(Z, linestyles='dotted') # old style
contour(Z, linestyles=':') # now also possible
The latter case is probably more useful than the first, but both work.
Any comments ?
Manuel
Index: cbook.py
===
--- cbook.py (revision 5009)
+++ cbook.py (working copy)
@@ -1068,6 +1068,16 @@
return result
+
+# a dict to cross-map linestyle arguments
+_linestyles = [('-', 'solid'),
+('--', 'dashed'),
+('-.', 'dashdot'),
+(':', 'dotted')]
+
+ls_mapper = dict(_linestyles)
+ls_mapper.update([(ls[1], ls[0]) for ls in _linestyles])
+
if __name__=='__main__':
assert( allequal([1,1,1]) )
assert(not allequal([1,1,0]) )
Index: collections.py
===
--- collections.py (revision 5009)
+++ collections.py (working copy)
@@ -228,14 +228,25 @@
ACCEPTS: ['solid' | 'dashed', 'dashdot', 'dotted' | (offset, on-off-dash-seq) ]
"""
try:
+dashd = backend_bases.GraphicsContextBase.dashd
if cbook.is_string_like(ls):
-dashes = [backend_bases.GraphicsContextBase.dashd[ls]]
+if dashd.has_key(ls):
+dashes = [dashd[ls]]
+elif cbook.ls_mapper.has_key(ls):
+dashes = [dashd[cbook.ls_mapper[ls]]]
+else:
+raise ValueError()
elif cbook.iterable(ls):
try:
dashes = []
for x in ls:
if cbook.is_string_like(x):
-dashes.append(backend_bases.GraphicsContextBase.dashd[ls])
+if dashd.has_key(x):
+dashes.append(dashd[x])
+elif cbook.ls_mapper.has_key(x):
+dashes.append(dashd[cbook.ls_mapper[x]])
+else:
+raise ValueError()
elif cbook.iterator(x) and len(x) == 2:
dashes.append(x)
else:
Index: lines.py
===
--- lines.py (revision 5009)
+++ lines.py (working copy)
@@ -11,7 +11,7 @@
from matplotlib import verbose
import artist
from artist import Artist
-from cbook import iterable, is_string_like, is_numlike
+from cbook import iterable, is_string_like, is_numlike, ls_mapper
from colors import colorConverter
from path import Path
from transforms import Affine2D, Bbox, TransformedPath
@@ -598,7 +598,10 @@
ACCEPTS: [ '-' | '--' | '-.' | ':' | 'steps' | 'steps-pre' | 'steps-mid' | 'steps-post' | 'None' | ' ' | '' ]
"""
if linestyle not in self._lineStyles:
-verbose.report('Unrecognized line style %s, %s' %
+if ls_mapper.has_key(linestyle):
+linestyle = ls_mapper[linestyle]
+else:
+verbose.report('Unrecognized line style %s, %s' %
(linestyle, type(linestyle)))
if linestyle in [' ','']:
linestyle = 'None'
import pylab
x = pylab.npy.arange(5)
pylab.plot(x,x, linestyle='-')
pylab.plot(x,x**2, linestyle='dashedu')
# makes not much sens but works in principle ;-)
pylab.scatter(x,pylab.npy.sqrt(x), s=150 ,linestyle='dashed')
pylab.scatter(x,0.5*pylab.npy.sqrt(x), s=150 ,linestyle=':')
pylab.scatter(x,0.25*pylab.npy.sqrt(x), s=150 ,linestyle=['-','--','-.',':','-'])
delta = 0.025
x = pylab.npy.arange(-3.0, 3.0, delta)
y = pylab.npy.arange(-2.0, 2.0, delta)
X, Y = pylab.npy.meshgrid(x, y)
Z1 = pylab.bivariate_normal(X, Y, 1.0, 1.0, 0.0, 0.0)
Z2 = pylab.bivariate_normal(X, Y, 1.5, 0.5, 1, 1)
# difference of Gaussians
Z = 10.0 * (Z2 - Z1)
linestyles = ['solid', 'dashed', 'dashdot', 'dotted',
'-','--','-.',':']
pylab.figure()
CS = pylab.contour(X, Y, Z, 8, linestyles=linestyles)
pylab.show()
-
This SF.net email is sponsored by: Microsoft
Defy all challenges. Microsoft(R) Visual Studio 2008.
http://clk.atdmt.com/MRT/go/vse012070mrt/direct/01/___
Matplotlib-devel mailing list
Matplotlib-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/matplotlib-devel