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

Skip to content

Commit 6d4dd00

Browse files
committed
a tkagg svg print fix
svn path=/trunk/matplotlib/; revision=3269
1 parent cc1f7e8 commit 6d4dd00

4 files changed

Lines changed: 40 additions & 6 deletions

File tree

examples/units/radian_demo.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
x = nx.arange(0, 15, 0.01) * radians
55

66
fig = figure()
7-
7+
fig.subplots_adjust(hspace=0.3)
88
ax = fig.add_subplot(211)
99
ax.plot(x, cos(x), xunits=radians)
1010

lib/matplotlib/backends/backend_tkagg.py

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -183,9 +183,14 @@ def print_figure(self, filename, dpi=None, facecolor='w', edgecolor='w',
183183

184184
if dpi is None: dpi = rcParams['savefig.dpi']
185185
agg = self.switch_backends(FigureCanvasAgg)
186-
agg.print_figure(filename, dpi, facecolor, edgecolor, orientation,
187-
**kwargs)
188-
self.figure.set_canvas(self)
186+
try: agg.print_figure(filename, dpi, facecolor, edgecolor, orientation,
187+
**kwargs)
188+
except:
189+
self.figure.set_canvas(self)
190+
raise
191+
else:
192+
self.figure.set_canvas(self)
193+
189194

190195
def motion_notify_event(self, event):
191196
x = event.x

lib/matplotlib/mlab.py

Lines changed: 28 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -788,6 +788,7 @@ def prctile(x, p = (0.0, 25.0, 50.0, 75.0, 100.0)):
788788
Return the percentiles of x. p can either be a sequence of
789789
percentil values or a scalar. If p is a sequence the i-th element
790790
of the return sequence is the p(i)-th percentile of x
791+
791792
"""
792793
x = sort(ravel(x))
793794
Nx = len(x)
@@ -800,6 +801,27 @@ def prctile(x, p = (0.0, 25.0, 50.0, 75.0, 100.0)):
800801
ind = where(ind>=Nx, Nx-1, ind)
801802
return take(x, ind)
802803

804+
def prctile_rank(x, p):
805+
"""
806+
return the for each element in x, return the rank 0..len(p) . Eg
807+
if p=(25, 50, 75), the return value will be a len(x) array with
808+
values in [0,1,2,3] where 0 indicates the value is less than the
809+
25th percentile, 1 indicates the value is >= the 25th and < 50th
810+
percentile, ... and 3 indicates the value is above the 75th
811+
percentile cutoff
812+
813+
p is either an array of percentiles in [0..100] or a scalar which
814+
indicates how many quantiles of data you want ranked
815+
"""
816+
817+
if not iterable(p):
818+
p = nx.arange(100./p, 100., 100./p)
819+
820+
if max(p)<=1 or min(p)<0 or max(p)>100:
821+
raise ValueError('percentiles should be in range 0..100, not 0..1')
822+
823+
ptiles = prctile(x, p)
824+
return nx.searchsorted(ptiles, x)
803825

804826
def center_matrix(M, dim=0):
805827
"""
@@ -895,6 +917,9 @@ def derivs(x,t):
895917
yout = rk4(derivs, y0, t)
896918
897919
920+
If you have access to scipy, you should probably be using the
921+
scipy.integrate tools rather than this function
922+
898923
"""
899924

900925
try: Ny = len(y0)
@@ -1515,7 +1540,7 @@ def angle(x1, y1, x2, y2):
15151540
return nx.nonzero(nx.greater_equal(nx.absolute(angles), nx.pi))
15161541

15171542
def inside_poly(points, verts):
1518-
""""
1543+
"""
15191544
points is a sequence of x,y points
15201545
verts is a sequence of x,y vertices of a poygon
15211546
@@ -1527,6 +1552,7 @@ def inside_poly(points, verts):
15271552
### the following code was written and submitted by Fernando Perez
15281553
### from the ipython numutils package under a BSD license
15291554
# begin fperez functions
1555+
15301556
"""
15311557
A set of convenient utilities for numerical work.
15321558
@@ -1563,6 +1589,7 @@ def inside_poly(points, verts):
15631589
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
15641590
OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
15651591
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
1592+
15661593
"""
15671594

15681595
import operator

lib/matplotlib/widgets.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -735,7 +735,9 @@ class MultiCursor:
735735
def __init__(self, canvas, axes, useblit=True, **lineprops):
736736
self.canvas = canvas
737737
self.axes = axes
738-
self.lines = [ax.axvline(1, visible=False, **lineprops) for ax in axes]
738+
xmin, xmax = axes[-1].get_xlim()
739+
xmid = 0.5*(xmin+xmax)
740+
self.lines = [ax.axvline(xmid, visible=False, **lineprops) for ax in axes]
739741

740742
self.visible = True
741743
self.useblit = useblit

0 commit comments

Comments
 (0)