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

Skip to content

Commit 140d122

Browse files
committed
Merged revisions 7598,7600 via svnmerge from
https://matplotlib.svn.sourceforge.net/svnroot/matplotlib/branches/v0_99_maint ........ r7598 | jdh2358 | 2009-08-30 08:35:12 -0500 (Sun, 30 Aug 2009) | 1 line applied Gael's ginput patch ........ r7600 | jdh2358 | 2009-08-30 11:22:38 -0500 (Sun, 30 Aug 2009) | 1 line some unit cleanup; fix sf bug 2846058 ........ svn path=/trunk/matplotlib/; revision=7601
1 parent 19fed4a commit 140d122

7 files changed

Lines changed: 41 additions & 20 deletions

File tree

examples/units/annotate_with_units.py

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
1-
2-
import pylab
1+
import matplotlib.pyplot as plt
32
from basic_units import cm
43

5-
fig = pylab.figure()
4+
fig = plt.figure()
65
ax = fig.add_subplot(111)
76

87

@@ -23,5 +22,5 @@
2322

2423
ax.set_xlim(0*cm, 4*cm)
2524
ax.set_ylim(0*cm, 4*cm)
26-
pylab.show()
25+
plt.show()
2726

examples/units/bar_demo2.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,11 +25,11 @@
2525

2626
ax3 = fig.add_subplot(2,2,3)
2727
ax3.bar(cms, cms, bottom=bottom, width=width, xunits=inch, yunits=cm)
28-
ax3.set_xlim(3, 6) # scalars are interpreted in current units
28+
ax3.set_xlim(2, 6) # scalars are interpreted in current units
2929

3030
ax4 = fig.add_subplot(2,2,4)
3131
ax4.bar(cms, cms, bottom=bottom, width=width, xunits=inch, yunits=inch)
3232
#fig.savefig('simple_conversion_plot.png')
33-
ax4.set_xlim(3*cm, 6*cm) # cm are converted to inches
33+
ax4.set_xlim(2*cm, 6*cm) # cm are converted to inches
3434

3535
show()

examples/units/radian_demo.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,15 +7,15 @@
77
from basic_units import radians, degrees, cos
88
from matplotlib.pyplot import figure, show
99

10-
x = np.arange(0, 15, 0.01) * radians
10+
x = [val*radians for val in np.arange(0, 15, 0.01)]
1111

1212
fig = figure()
1313
fig.subplots_adjust(hspace=0.3)
1414

1515
ax = fig.add_subplot(211)
16-
ax.plot(x, cos(x), xunits=radians)
16+
line1, = ax.plot(x, cos(x), xunits=radians)
1717

1818
ax = fig.add_subplot(212)
19-
ax.plot(x, cos(x), xunits=degrees)
19+
line2, = ax.plot(x, cos(x), xunits=degrees)
2020

2121
show()

lib/matplotlib/axes.py

Lines changed: 22 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -203,10 +203,24 @@ def _xy_from_xy(self, x, y):
203203
if self.axes.xaxis is not None and self.axes.yaxis is not None:
204204
bx = self.axes.xaxis.update_units(x)
205205
by = self.axes.yaxis.update_units(y)
206-
if bx:
207-
x = self.axes.convert_xunits(x)
208-
if by:
209-
y = self.axes.convert_yunits(y)
206+
207+
if self.command!='plot':
208+
# the Line2D class can handle unitized data, with
209+
# support for post hoc unit changes etc. Other mpl
210+
# artists, eg Polygon which _process_plot_var_args
211+
# also serves on calls to fill, cannot. So this is a
212+
# hack to say: if you are not "plot", which is
213+
# creating Line2D, then convert the data now to
214+
# floats. If you are plot, pass the raw data through
215+
# to Line2D which will handle the conversion. So
216+
# polygons will not support post hoc conversions of
217+
# the unit type since they are not storing the orig
218+
# data. Hopefully we can rationalize this at a later
219+
# date - JDH
220+
if bx:
221+
x = self.axes.convert_xunits(x)
222+
if by:
223+
y = self.axes.convert_yunits(y)
210224

211225
x = np.atleast_1d(x) #like asanyarray, but converts scalar to array
212226
y = np.atleast_1d(y)
@@ -4270,10 +4284,14 @@ def make_iterable(x):
42704284
if self.xaxis is not None:
42714285
left = self.convert_xunits( left )
42724286
width = self.convert_xunits( width )
4287+
if xerr is not None:
4288+
xerr = self.convert_xunits( xerr )
42734289

42744290
if self.yaxis is not None:
42754291
bottom = self.convert_yunits( bottom )
42764292
height = self.convert_yunits( height )
4293+
if yerr is not None:
4294+
yerr = self.convert_yunits( yerr )
42774295

42784296
if align == 'edge':
42794297
pass

lib/matplotlib/blocking_input.py

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,6 @@
1717
Note: Subclass of BlockingMouseInput. Used by clabel
1818
"""
1919

20-
import time
21-
import numpy as np
22-
2320
from matplotlib import path, verbose
2421
from matplotlib.cbook import is_sequence_of_strings
2522

@@ -151,7 +148,7 @@ def mouse_event(self):
151148
button = event.button
152149

153150
if button == self.button_pop:
154-
self.mouse_event_pop(event,-1)
151+
self.mouse_event_pop(event)
155152
elif button == self.button_stop:
156153
self.mouse_event_stop(event)
157154
else:
@@ -162,7 +159,7 @@ def key_event(self):
162159
Process a key click event. This maps certain keys to appropriate
163160
mouse click events.
164161
'''
165-
162+
166163
event = self.events[-1]
167164
key = event.key.lower()
168165

lib/matplotlib/collections.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -819,7 +819,9 @@ def __init__(self, segments, # Can be None.
819819
def set_segments(self, segments):
820820
if segments is None: return
821821
_segments = []
822+
822823
for seg in segments:
824+
823825
if not np.ma.isMaskedArray(seg):
824826
seg = np.asarray(seg, np.float_)
825827
_segments.append(seg)

lib/matplotlib/figure.py

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,12 +12,11 @@
1212
1313
"""
1414
import numpy as np
15-
import time
1615

1716
import artist
1817
from artist import Artist, allow_rasterization
1918
from axes import Axes, SubplotBase, subplot_class_factory
20-
from cbook import flatten, allequal, Stack, iterable, dedent
19+
from cbook import flatten, allequal, Stack, iterable
2120
import _image
2221
import colorbar as cbar
2322
from image import FigureImage
@@ -1118,6 +1117,12 @@ def ginput(self, n=1, timeout=30, show_clicks=True, mouse_add=1, mouse_pop=3, mo
11181117
11191118
Right clicking cancels last input.
11201119
1120+
The buttons used for the various actions (adding points, removing
1121+
points, terminating the inputs) can be overriden via the
1122+
arguments *mouse_add*, *mouse_pop* and *mouse_stop*, that give
1123+
the associated mouse button: 1 for left, 2 for middle, 3 for
1124+
right.
1125+
11211126
The keyboard can also be used to select points in case your mouse
11221127
does not have one or more of the buttons. The delete and backspace
11231128
keys act like right clicking (i.e., remove last point), the enter key

0 commit comments

Comments
 (0)