Skip to content

Commit 1103385

Browse files
committed
minor modifications to make more py3 friendly
1 parent e7ca3a3 commit 1103385

File tree

5 files changed

+38
-34
lines changed

5 files changed

+38
-34
lines changed

lib/matplotlib/tight_layout.py

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@
1010
1111
"""
1212

13+
import warnings
14+
1315
import matplotlib
1416
from matplotlib.transforms import TransformedBbox, Bbox
1517

@@ -44,7 +46,7 @@ def auto_adjust_subplotpars(fig, renderer,
4446
information of subplot itself, but uses what is given by
4547
*nrows_ncols* and *num1num2_list* parameteres. Also, the results could be
4648
incorrect if some subplots have ``adjustable=datalim``.
47-
49+
4850
Parameters:
4951
5052
nrows_ncols
@@ -80,7 +82,7 @@ def auto_adjust_subplotpars(fig, renderer,
8082
hpad_inches = w_pad * FontProperties(size=rcParams["font.size"]).get_size_in_points() / renderer.dpi
8183
else:
8284
hpad_inches = pad_inches
83-
85+
8486

8587
if len(subplot_list) == 0:
8688
raise RuntimeError("")
@@ -96,18 +98,18 @@ def auto_adjust_subplotpars(fig, renderer,
9698
else: margin_right = None
9799
if _top: margin_top = 1. - _top
98100
else: margin_top = None
99-
101+
100102
vspaces = [[] for i in range((rows+1)*cols)]
101103
hspaces = [[] for i in range(rows*(cols+1))]
102-
104+
103105
union = Bbox.union
104106

105107
if ax_bbox_list is None:
106108
ax_bbox_list = []
107109
for subplots in subplot_list:
108110
ax_bbox = union([ax.get_position(original=True) for ax in subplots])
109111
ax_bbox_list.append(ax_bbox)
110-
112+
111113
for subplots, ax_bbox, (num1, num2) in zip(subplot_list,
112114
ax_bbox_list,
113115
num1num2_list):
@@ -132,7 +134,7 @@ def auto_adjust_subplotpars(fig, renderer,
132134

133135
else:
134136
row2, col2 = divmod(num2, cols)
135-
137+
136138
for row_i in range(row1, row2+1):
137139
# left
138140
hspaces[row_i * (cols+1) + col1].append(_get_left(tight_bbox, ax_bbox))
@@ -153,7 +155,7 @@ def auto_adjust_subplotpars(fig, renderer,
153155
if not margin_left:
154156
margin_left = max([sum(s) for s in hspaces[::cols+1]] + [0])
155157
margin_left += pad_inches / fig_width_inch
156-
158+
157159
if not margin_right:
158160
margin_right = max([sum(s) for s in hspaces[cols::cols+1]] + [0])
159161
margin_right += pad_inches / fig_width_inch
@@ -165,7 +167,7 @@ def auto_adjust_subplotpars(fig, renderer,
165167
if not margin_bottom:
166168
margin_bottom = max([sum(s) for s in vspaces[-cols:]] + [0])
167169
margin_bottom += pad_inches / fig_height_inch
168-
170+
169171

170172
kwargs = dict(left=margin_left,
171173
right=1-margin_right,
@@ -187,7 +189,7 @@ def auto_adjust_subplotpars(fig, renderer,
187189
kwargs["hspace"]=vspace/v_axes
188190

189191
return kwargs
190-
192+
191193

192194
def get_renderer(fig):
193195
if fig._cachedRenderer:
@@ -199,7 +201,7 @@ def get_renderer(fig):
199201
renderer = canvas.get_renderer()
200202
else:
201203
# not sure if this can happen
202-
print "tight_layout : falling back to Agg renderer"
204+
warnings.warn("tight_layout : falling back to Agg renderer")
203205
from matplotlib.backends.backend_agg import FigureCanvasAgg
204206
canvas = FigureCanvasAgg(fig)
205207
renderer = canvas.get_renderer()

lib/mpl_toolkits/axes_grid1/axes_size.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -280,8 +280,7 @@ def __init__(self, ax, direction):
280280
try:
281281
self._get_func = self._get_func_map[direction]
282282
except KeyError:
283-
print "direction must be one of left, right, bottom, top"
284-
raise
283+
raise KeyError("direction must be one of left, right, bottom, top")
285284

286285
def __call__(self, renderer):
287286
vl = [self._get_func(ax.get_tightbbox(renderer, False),

lib/mpl_toolkits/axisartist/angle_helper.py

Lines changed: 18 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
A = np.array
77

88
from mpl_toolkits.axisartist.grid_finder import ExtremeFinderSimple
9+
from __future__ import print_function
910

1011
def select_step_degree(dv):
1112

@@ -433,38 +434,38 @@ def _adjust_extremes(self, lon_min, lon_max, lat_min, lat_max):
433434
#print select_step360(20.5+21.2/3600., 20.5+33.3/3600., 5)
434435

435436
# test threshold factor
436-
print select_step360(20.5+11.2/3600., 20.5+53.3/3600., 5,
437-
threshold_factor=60)
437+
print(select_step360(20.5+11.2/3600., 20.5+53.3/3600., 5,
438+
threshold_factor=60))
438439

439-
print select_step360(20.5+11.2/3600., 20.5+53.3/3600., 5,
440-
threshold_factor=1)
440+
print(select_step360(20.5+11.2/3600., 20.5+53.3/3600., 5,
441+
threshold_factor=1))
441442

442443
fmt = FormatterDMS()
443444
#print fmt("left", 60, [0, -30, -60])
444-
print fmt("left", 600, [12301, 12302, 12303])
445+
print(fmt("left", 600, [12301, 12302, 12303]))
445446

446-
print select_step360(20.5+21.2/3600., 20.5+21.4/3600., 5)
447-
print fmt("left", 36000, [738210, 738215, 738220])
448-
print fmt("left", 360000, [7382120, 7382125, 7382130])
449-
print fmt("left", 1., [45, 46, 47])
450-
print fmt("left", 10., [452, 453, 454])
447+
print(select_step360(20.5+21.2/3600., 20.5+21.4/3600., 5))
448+
print(fmt("left", 36000, [738210, 738215, 738220]))
449+
print(fmt("left", 360000, [7382120, 7382125, 7382130]))
450+
print(fmt("left", 1., [45, 46, 47]))
451+
print(fmt("left", 10., [452, 453, 454]))
451452

452453
if 0:
453-
print select_step360(20+21.2/60., 21+33.3/60., 5)
454-
print select_step360(20.5+21.2/3600., 20.5+33.3/3600., 5)
455-
print select_step360(20+21.2/60., 20+53.3/60., 5)
454+
print(select_step360(20+21.2/60., 21+33.3/60., 5))
455+
print(select_step360(20.5+21.2/3600., 20.5+33.3/3600., 5))
456+
print(select_step360(20+21.2/60., 20+53.3/60., 5))
456457

457458
###
458459
levs, n, factor = select_step360(20.5+21.2/3600., 20.5+27.25/3600., 5)
459460
levs = levs * 0.1
460461
fmt = FormatterDMS()
461462
#print fmt("left", 60, [0, -30, -60])
462-
print fmt("left", factor, levs)
463+
print(fmt("left", factor, levs))
463464

464465

465-
print select_step(-180, 180, 10, hour=False)
466-
print select_step(-12, 12, 10, hour=True)
466+
print(select_step(-180, 180, 10, hour=False))
467+
print(select_step(-12, 12, 10, hour=True))
467468

468469
fmt = FormatterDMS()
469470
#print fmt("left", 60, [0, -30, -60])
470-
print fmt("left", 3600, [0, -30, -60])
471+
print(fmt("left", 3600, [0, -30, -60]))

lib/mpl_toolkits/axisartist/clip_path.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
11
import numpy as np
22
from math import degrees
33
import math
4+
import warnings
45

56
def atan2(dy, dx):
67
if dx == 0 and dx == 0:
7-
print "warning"
8+
warnings.warn("dx and dy is 0")
89
return 0
910
else:
1011
return math.atan2(dy, dx)
@@ -28,7 +29,7 @@ def clip(xlines, ylines, x0, clip="right", xdir=True, ydir=True):
2829
ysign = 1
2930
else:
3031
ysign = -1
31-
32+
3233

3334
for x, y in zip(xlines, ylines):
3435

@@ -95,7 +96,7 @@ def clip_line_to_rect(xline, yline, bbox):
9596

9697
xdir = x1 > x0
9798
ydir = y1 > y0
98-
99+
99100
if x1 > x0:
100101
lx1, ly1, c_right_ = clip([xline], [yline], x1, clip="right", xdir=xdir, ydir=ydir)
101102
lx2, ly2, c_left_ = clip(lx1, ly1, x0, clip="left", xdir=xdir, ydir=ydir)
@@ -110,7 +111,7 @@ def clip_line_to_rect(xline, yline, bbox):
110111
ly3, lx3, c_top_ = clip(ly2, lx2, y0, clip="right", xdir=ydir, ydir=xdir)
111112
ly4, lx4, c_bottom_ = clip(ly3, lx3, y1, clip="left", xdir=ydir, ydir=xdir)
112113

113-
114+
114115
# lx1, ly1, c_right_ = clip([xline], [yline], x1, clip="right")
115116
# lx2, ly2, c_left_ = clip(lx1, ly1, x0, clip="left")
116117
# ly3, lx3, c_top_ = clip(ly2, lx2, y1, clip="right")

lib/mpl_toolkits/axisartist/grid_finder.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
import matplotlib.ticker as mticker
88
from matplotlib.transforms import Transform
99

10+
from __future__ import print_function
1011

1112
# extremes finder
1213

@@ -345,4 +346,4 @@ def __call__(self, direction, factor, values):
345346

346347
fmt = FormatterPrettyPrint()
347348

348-
print fmt("left", None, locs)
349+
print(fmt("left", None, locs))

0 commit comments

Comments
 (0)