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

Skip to content

Commit 9a5b7c1

Browse files
committed
fixed an xorig conversion bug
svn path=/trunk/matplotlib/; revision=3121
1 parent ca285c7 commit 9a5b7c1

2 files changed

Lines changed: 50 additions & 7 deletions

File tree

examples/units/evans_test2.py

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
from basic_units import radians, degrees
2+
from pylab import figure, show, nx
3+
from matplotlib.cbook import iterable
4+
import math
5+
6+
def cos( x ):
7+
if ( iterable(x) ):
8+
result = []
9+
for val in x:
10+
result.append( math.cos( val.convert_to( radians ).get_value() ) )
11+
return result
12+
else:
13+
return math.cos( x.convert_to( radians ).get_value() )
14+
15+
# the following command strips away the units and
16+
# therefore demonstrates nothing. The valeus are
17+
# the same for both graphs. In order to really
18+
# use the units, the list of values passed into
19+
# the plot function must be a unitized type.
20+
21+
# x = nx.arange(0, 15, 0.01) * radians
22+
23+
x = []
24+
for i in range(0, 1500):
25+
x.append( i*0.01*radians )
26+
27+
fig = figure()
28+
29+
ax = fig.add_subplot(211)
30+
ax.plot(x, cos(x), xunits=radians)
31+
ax.set_xlabel('radians')
32+
33+
ax = fig.add_subplot(212)
34+
ax.plot(x, cos(x), xunits=degrees)
35+
ax.set_xlabel('degrees')
36+
37+
show()
38+

lib/matplotlib/axes.py

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -227,16 +227,21 @@ def set_patchprops(self, fill_poly, **kwargs):
227227
func(val)
228228

229229
def _xy_from_y(self, y):
230-
y = ma.asarray(y)
230+
try: y = ma.asarray(y)
231+
except TypeError: return None, None
232+
except ValueError: return None, None
231233
if len(y.shape) == 1:
232234
y = y[:,newaxis]
233235
nr, nc = y.shape
234236
x = arange(nr)
235237
return x,y
236238

237239
def _xy_from_xy(self, x, y):
238-
x = ma.asarray(x)
239-
y = ma.asarray(y)
240+
try:
241+
x = ma.asarray(x)
242+
y = ma.asarray(y)
243+
except TypeError: return None, None
244+
except ValueError: return None, None
240245
if len(x.shape) == 1:
241246
x = x[:,newaxis]
242247
if len(y.shape) == 1:
@@ -261,7 +266,7 @@ def _plot_1_arg(self, y, **kwargs):
261266
yorig = y
262267
x, y = self._xy_from_y(yorig)
263268

264-
multicol = y.shape[1]>1
269+
multicol = x is not None and y is not None and y.shape[1]>1
265270

266271
if multicol:
267272

@@ -292,7 +297,7 @@ def _plot_2_args(self, tup2, **kwargs):
292297

293298
linestyle, marker, color = _process_plot_format(fmt)
294299

295-
multicol = y.shape[1]>1
300+
multicol = x is not None and y is not None and y.shape[1]>1
296301

297302

298303
def makeline(x, y):
@@ -317,7 +322,7 @@ def makeline(x, y):
317322

318323
xorig, yorig = tup2
319324
x, y = self._xy_from_xy(xorig, yorig)
320-
multicol = y.shape[1]>1
325+
multicol = x is not None and y is not None and y.shape[1]>1
321326

322327
def makeline(x, y):
323328
color = self._get_next_cycle_color()
@@ -354,7 +359,7 @@ def _plot_3_args(self, tup3, **kwargs):
354359

355360
xorig, yorig, fmt = tup3
356361
x, y = self._xy_from_xy(xorig, yorig)
357-
multicol = y.shape[1]>1
362+
multicol = x is not None and y is not None and y.shape[1]>1
358363

359364
linestyle, marker, color = _process_plot_format(fmt)
360365

0 commit comments

Comments
 (0)