Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit ec45d17

Browse files
committed
backend_ps fix redux
svn path=/trunk/matplotlib/; revision=732
1 parent 2d95ffb commit ec45d17

5 files changed

Lines changed: 322 additions & 12 deletions

File tree

examples/backend_driver.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@ def drive(backend, python='python2.3'):
103103
backends = ['PS', 'GD', 'Paint', 'Agg', 'Template']
104104
#backends.extend([ 'GTK', 'WX', 'TkAgg'])
105105
#backends = [ 'Agg']
106-
backends = [ 'SVG', 'PS', 'Agg', 'Template']
106+
backends = ['PS', 'Agg']
107107

108108
python = 'python2.3'
109109
for backend in backends:

examples/color_demo.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,15 +4,15 @@
44
55
1) as a single letter string, ala matab
66
7-
2) as an html style hex string
7+
2) as an html style hex string or html color name
88
99
3) as an R,G,B tuple, where R,G,B, range from 0-1
1010
1111
See help(colors) for more info.
1212
"""
1313
from matplotlib.matlab import *
1414

15-
subplot(111, axisbg=(0.1843, 0.3098, 0.3098))
15+
subplot(111, axisbg='darkslategray')
1616
#subplot(111, axisbg='#ababab')
1717
t = arange(0.0, 2.0, 0.01)
1818
s = sin(2*pi*t)

lib/matplotlib/backends/backend_ps.py

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121

2222
from matplotlib import get_data_path
2323

24-
from matplotlib.numerix import fromstring, UInt8, Float32
24+
from matplotlib.numerix import fromstring, UInt8, Float32, equal, alltrue
2525
import binascii
2626

2727

@@ -55,6 +55,23 @@ def _nums_to_str(*args):
5555
_type42 = []
5656

5757

58+
def seq_allequal(seq1, seq2):
59+
"""
60+
seq1 and seq2 are either None or sequences or numerix arrays
61+
Return True if both are None or both are seqs with identical
62+
elements
63+
"""
64+
if seq1 is None:
65+
return seq2 is None
66+
67+
if seq2 is None:
68+
return False
69+
#ok, neither are None:, assuming iterable
70+
71+
if len(seq1) != len(seq2): return False
72+
return alltrue(equal(seq1, seq2))
73+
74+
5875
class RendererPS(RendererBase):
5976
"""
6077
The renderer handles all the drawing primitives using a graphics
@@ -101,7 +118,7 @@ def set_linecap(self, linecap):
101118
def set_linedash(self, offset, seq):
102119
if self.linedash is not None:
103120
oldo, oldseq = self.linedash
104-
if offset==oldo and seq==oldseq: return
121+
if seq_allequal(seq, oldseq): return
105122

106123
if seq is not None and len(seq):
107124
s="[%s] %d setdash\n"%(_nums_to_str(*seq), offset)

lib/matplotlib/colors.py

Lines changed: 294 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -17,23 +17,308 @@
1717
k : black
1818
w : white
1919
20-
2120
For a greater range of colors, you have two options. You can specify
2221
the color using an html hex string, as in
2322
2423
color = '#eeefff'
2524
2625
or you can pass an R,G,B tuple, where each of R,G,B are in the range
2726
[0,1].
27+
28+
Finally, legal html names for colors, like 'red', 'burlywood' and
29+
'chartreuse' are supported.
2830
"""
31+
2932
from numerix import MLab, array, arange, take, put, Float, Int, where, \
3033
zeros, asarray, sort, searchsorted, sometrue, ravel, divide
3134
from types import IntType, FloatType
3235
from cbook import True, False, enumerate, is_string_like, iterable
3336

37+
cnames = {
38+
'aliceblue' : '#F0F8FF',
39+
'antiquewhite' : '#FAEBD7',
40+
'aqua' : '#00FFFF',
41+
'aquamarine' : '#7FFFD4',
42+
'azure' : '#F0FFFF',
43+
'beige' : '#F5F5DC',
44+
'bisque' : '#FFE4C4',
45+
'black' : '#000000',
46+
'blanchedalmond' : '#FFEBCD',
47+
'blue' : '#0000FF',
48+
'blueviolet' : '#8A2BE2',
49+
'brown' : '#A52A2A',
50+
'burlywood' : '#DEB887',
51+
'cadetblue' : '#5F9EA0',
52+
'chartreuse' : '#7FFF00',
53+
'chocolate' : '#D2691E',
54+
'coral' : '#FF7F50',
55+
'cornflowerblue' : '#6495ED',
56+
'cornsilk' : '#FFF8DC',
57+
'crimson' : '#DC143C',
58+
'cyan' : '#00FFFF',
59+
'darkblue' : '#00008B',
60+
'darkcyan' : '#008B8B',
61+
'darkgoldenrod' : '#B8860B',
62+
'darkgray' : '#A9A9A9',
63+
'darkgreen' : '#006400',
64+
'darkkhaki' : '#BDB76B',
65+
'darkmagenta' : '#8B008B',
66+
'darkolivegreen' : '#556B2F',
67+
'darkorange' : '#FF8C00',
68+
'darkorchid' : '#9932CC',
69+
'darkred' : '#8B0000',
70+
'darksalmon' : '#E9967A',
71+
'darkseagreen' : '#8FBC8F',
72+
'darkslateblue' : '#483D8B',
73+
'darkslategray' : '#2F4F4F',
74+
'darkturquoise' : '#00CED1',
75+
'darkviolet' : '#9400D3',
76+
'deeppink' : '#FF1493',
77+
'deepskyblue' : '#00BFFF',
78+
'dimgray' : '#696969',
79+
'dodgerblue' : '#1E90FF',
80+
'firebrick' : '#B22222',
81+
'floralwhite' : '#FFFAF0',
82+
'forestgreen' : '#228B22',
83+
'fuchsia' : '#FF00FF',
84+
'gainsboro' : '#DCDCDC',
85+
'ghostwhite' : '#F8F8FF',
86+
'gold' : '#FFD700',
87+
'goldenrod' : '#DAA520',
88+
'gray' : '#808080',
89+
'green' : '#008000',
90+
'greenyellow' : '#ADFF2F',
91+
'honeydew' : '#F0FFF0',
92+
'hotpink' : '#FF69B4',
93+
'indianred' : '#CD5C5C',
94+
'indigo' : '#4B0082',
95+
'ivory' : '#FFFFF0',
96+
'khaki' : '#F0E68C',
97+
'lavender' : '#E6E6FA',
98+
'lavenderblush' : '#FFF0F5',
99+
'lawngreen' : '#7CFC00',
100+
'lemonchiffon' : '#FFFACD',
101+
'lightblue' : '#ADD8E6',
102+
'lightcoral' : '#F08080',
103+
'lightcyan' : '#E0FFFF',
104+
'lightgoldenrodyellow' : '#FAFAD2',
105+
'lightgreen' : '#90EE90',
106+
'lightgrey' : '#D3D3D3',
107+
'lightpink' : '#FFB6C1',
108+
'lightsalmon' : '#FFA07A',
109+
'lightseagreen' : '#20B2AA',
110+
'lightskyblue' : '#87CEFA',
111+
'lightslategray' : '#778899',
112+
'lightsteelblue' : '#B0C4DE',
113+
'lightyellow' : '#FFFFE0',
114+
'lime' : '#00FF00',
115+
'limegreen' : '#32CD32',
116+
'linen' : '#FAF0E6',
117+
'magenta' : '#FF00FF',
118+
'maroon' : '#800000',
119+
'mediumaquamarine' : '#66CDAA',
120+
'mediumblue' : '#0000CD',
121+
'mediumorchid' : '#BA55D3',
122+
'mediumpurple' : '#9370DB',
123+
'mediumseagreen' : '#3CB371',
124+
'mediumslateblue' : '#7B68EE',
125+
'mediumspringgreen' : '#00FA9A',
126+
'mediumturquoise' : '#48D1CC',
127+
'mediumvioletred' : '#C71585',
128+
'midnightblue' : '#191970',
129+
'mintcream' : '#F5FFFA',
130+
'mistyrose' : '#FFE4E1',
131+
'moccasin' : '#FFE4B5',
132+
'navajowhite' : '#FFDEAD',
133+
'navy' : '#000080',
134+
'oldlace' : '#FDF5E6',
135+
'olive' : '#808000',
136+
'olivedrab' : '#6B8E23',
137+
'orange' : '#FFA500',
138+
'orangered' : '#FF4500',
139+
'orchid' : '#DA70D6',
140+
'palegoldenrod' : '#EEE8AA',
141+
'palegreen' : '#98FB98',
142+
'palevioletred' : '#AFEEEE',
143+
'papayawhip' : '#FFEFD5',
144+
'peachpuff' : '#FFDAB9',
145+
'peru' : '#CD853F',
146+
'pink' : '#FFC0CB',
147+
'plum' : '#DDA0DD',
148+
'powderblue' : '#B0E0E6',
149+
'purple' : '#800080',
150+
'red' : '#FF0000',
151+
'rosybrown' : '#BC8F8F',
152+
'royalblue' : '#4169E1',
153+
'saddlebrown' : '#8B4513',
154+
'salmon' : '#FA8072',
155+
'sandybrown' : '#FAA460',
156+
'seagreen' : '#2E8B57',
157+
'seashell' : '#FFF5EE',
158+
'sienna' : '#A0522D',
159+
'silver' : '#C0C0C0',
160+
'skyblue' : '#87CEEB',
161+
'slateblue' : '#6A5ACD',
162+
'slategray' : '#708090',
163+
'snow' : '#FFFAFA',
164+
'springgreen' : '#00FF7F',
165+
'steelblue' : '#4682B4',
166+
'tan' : '#D2B48C',
167+
'teal' : '#008080',
168+
'thistle' : '#D8BFD8',
169+
'tomato' : '#FF6347',
170+
'turquoise' : '#40E0D0',
171+
'violet' : '#EE82EE',
172+
'wheat' : '#F5DEB3',
173+
'white' : '#FFFFFF',
174+
'whitesmoke' : '#F5F5F5',
175+
'yellow' : '#FFFF00',
176+
'yellowgreen' : '#9ACD32',
177+
'black' : '#000000',
178+
'navy' : '#000080',
179+
'darkblue' : '#00008B',
180+
'mediumblue' : '#0000CD',
181+
'blue' : '#0000FF',
182+
'darkgreen' : '#006400',
183+
'green' : '#008000',
184+
'teal' : '#008080',
185+
'darkcyan' : '#008B8B',
186+
'deepskyblue' : '#00BFFF',
187+
'darkturquoise' : '#00CED1',
188+
'mediumspringgreen' : '#00FA9A',
189+
'lime' : '#00FF00',
190+
'springgreen' : '#00FF7F',
191+
'aqua' : '#00FFFF',
192+
'cyan' : '#00FFFF',
193+
'midnightblue' : '#191970',
194+
'dodgerblue' : '#1E90FF',
195+
'lightseagreen' : '#20B2AA',
196+
'forestgreen' : '#228B22',
197+
'seagreen' : '#2E8B57',
198+
'darkslategray' : '#2F4F4F',
199+
'limegreen' : '#32CD32',
200+
'mediumseagreen' : '#3CB371',
201+
'turquoise' : '#40E0D0',
202+
'royalblue' : '#4169E1',
203+
'steelblue' : '#4682B4',
204+
'darkslateblue' : '#483D8B',
205+
'mediumturquoise' : '#48D1CC',
206+
'indigo' : '#4B0082',
207+
'darkolivegreen' : '#556B2F',
208+
'cadetblue' : '#5F9EA0',
209+
'cornflowerblue' : '#6495ED',
210+
'mediumaquamarine' : '#66CDAA',
211+
'dimgray' : '#696969',
212+
'slateblue' : '#6A5ACD',
213+
'olivedrab' : '#6B8E23',
214+
'slategray' : '#708090',
215+
'lightslategray' : '#778899',
216+
'mediumslateblue' : '#7B68EE',
217+
'lawngreen' : '#7CFC00',
218+
'chartreuse' : '#7FFF00',
219+
'aquamarine' : '#7FFFD4',
220+
'maroon' : '#800000',
221+
'purple' : '#800080',
222+
'olive' : '#808000',
223+
'gray' : '#808080',
224+
'skyblue' : '#87CEEB',
225+
'lightskyblue' : '#87CEFA',
226+
'blueviolet' : '#8A2BE2',
227+
'darkred' : '#8B0000',
228+
'darkmagenta' : '#8B008B',
229+
'saddlebrown' : '#8B4513',
230+
'darkseagreen' : '#8FBC8F',
231+
'lightgreen' : '#90EE90',
232+
'mediumpurple' : '#9370DB',
233+
'darkviolet' : '#9400D3',
234+
'palegreen' : '#98FB98',
235+
'darkorchid' : '#9932CC',
236+
'yellowgreen' : '#9ACD32',
237+
'sienna' : '#A0522D',
238+
'brown' : '#A52A2A',
239+
'darkgray' : '#A9A9A9',
240+
'lightblue' : '#ADD8E6',
241+
'greenyellow' : '#ADFF2F',
242+
'palevioletred' : '#AFEEEE',
243+
'lightsteelblue' : '#B0C4DE',
244+
'powderblue' : '#B0E0E6',
245+
'firebrick' : '#B22222',
246+
'darkgoldenrod' : '#B8860B',
247+
'mediumorchid' : '#BA55D3',
248+
'rosybrown' : '#BC8F8F',
249+
'darkkhaki' : '#BDB76B',
250+
'silver' : '#C0C0C0',
251+
'mediumvioletred' : '#C71585',
252+
'indianred' : '#CD5C5C',
253+
'peru' : '#CD853F',
254+
'chocolate' : '#D2691E',
255+
'tan' : '#D2B48C',
256+
'lightgrey' : '#D3D3D3',
257+
'thistle' : '#D8BFD8',
258+
'orchid' : '#DA70D6',
259+
'goldenrod' : '#DAA520',
260+
'crimson' : '#DC143C',
261+
'gainsboro' : '#DCDCDC',
262+
'plum' : '#DDA0DD',
263+
'burlywood' : '#DEB887',
264+
'lightcyan' : '#E0FFFF',
265+
'lavender' : '#E6E6FA',
266+
'darksalmon' : '#E9967A',
267+
'violet' : '#EE82EE',
268+
'palegoldenrod' : '#EEE8AA',
269+
'lightcoral' : '#F08080',
270+
'khaki' : '#F0E68C',
271+
'aliceblue' : '#F0F8FF',
272+
'honeydew' : '#F0FFF0',
273+
'azure' : '#F0FFFF',
274+
'wheat' : '#F5DEB3',
275+
'beige' : '#F5F5DC',
276+
'whitesmoke' : '#F5F5F5',
277+
'mintcream' : '#F5FFFA',
278+
'ghostwhite' : '#F8F8FF',
279+
'salmon' : '#FA8072',
280+
'sandybrown' : '#FAA460',
281+
'antiquewhite' : '#FAEBD7',
282+
'linen' : '#FAF0E6',
283+
'lightgoldenrodyellow' : '#FAFAD2',
284+
'oldlace' : '#FDF5E6',
285+
'red' : '#FF0000',
286+
'fuchsia' : '#FF00FF',
287+
'magenta' : '#FF00FF',
288+
'deeppink' : '#FF1493',
289+
'orangered' : '#FF4500',
290+
'tomato' : '#FF6347',
291+
'hotpink' : '#FF69B4',
292+
'coral' : '#FF7F50',
293+
'darkorange' : '#FF8C00',
294+
'lightsalmon' : '#FFA07A',
295+
'orange' : '#FFA500',
296+
'lightpink' : '#FFB6C1',
297+
'pink' : '#FFC0CB',
298+
'gold' : '#FFD700',
299+
'peachpuff' : '#FFDAB9',
300+
'navajowhite' : '#FFDEAD',
301+
'moccasin' : '#FFE4B5',
302+
'bisque' : '#FFE4C4',
303+
'mistyrose' : '#FFE4E1',
304+
'blanchedalmond' : '#FFEBCD',
305+
'papayawhip' : '#FFEFD5',
306+
'lavenderblush' : '#FFF0F5',
307+
'seashell' : '#FFF5EE',
308+
'cornsilk' : '#FFF8DC',
309+
'lemonchiffon' : '#FFFACD',
310+
'floralwhite' : '#FFFAF0',
311+
'snow' : '#FFFAFA',
312+
'yellow' : '#FFFF00',
313+
'lightyellow' : '#FFFFE0',
314+
'ivory' : '#FFFFF0',
315+
'white' : '#FFFFFF',
316+
}
317+
34318
def looks_like_color(c):
35319
if is_string_like(c):
36-
if len(c)==1: return True
320+
if cnames.has_key(c): return True
321+
elif len(c)==1: return True
37322
elif len(s)==7 and c.startswith('#') and len(s)==7: return True
38323
else: return False
39324
elif iterable(c) and len(c)==3:
@@ -86,12 +371,15 @@ def to_rgb(self, arg):
86371
try: self.cache[arg]
87372
except KeyError: pass
88373

89-
374+
color = None
90375
try: float(arg)
91376
except:
92-
if is_string_like(arg) and len(arg)==7 and arg[0]=='#':
93-
color = hex2color(arg)
94-
else:
377+
if is_string_like(arg):
378+
hex = cnames.get(arg)
379+
if hex is not None: arg = hex
380+
if len(arg)==7 and arg[0]=='#':
381+
color = hex2color(arg)
382+
if color is None:
95383
# see if it looks like rgb. If so, just return arg
96384
try: float(arg[2])
97385
except: color = self.colors.get(arg, (0.0, 0.0, 0.0))

0 commit comments

Comments
 (0)