8000 Merge pull request #13878 from anntzer/floating_axes · matplotlib/matplotlib@a58f1c6 · GitHub
[go: up one dir, main page]

Skip to content

Commit a58f1c6

Browse files
authored
Merge pull request #13878 from anntzer/floating_axes
Style fixes for floating_axes.
2 parents 652478d + e499ffe commit a58f1c6

File tree

2 files changed

+26
-36
lines changed

2 files changed

+26
-36
lines changed

.flake8

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,6 @@ per-file-ignores =
5959
lib/mpl_toolkits/axes_grid1/colorbar.py: E225, E501
6060
lib/mpl_toolkits/axisartist/angle_helper.py: E221
6161
lib/mpl_toolkits/axisartist/clip_path.py: E225
62-
lib/mpl_toolkits/axisartist/floating_axes.py: E225, E402, E501
6362
lib/mpl_toolkits/axisartist/grid_helper_curvelinear.py: E225, E501
6463

6564
doc/conf.py: E402, E501

lib/mpl_toolkits/axisartist/floating_axes.py

Lines changed: 26 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -2,19 +2,27 @@
22
An experimental support for curvilinear grid.
33
"""
44

5-
import functools
6-
75
# TODO :
86
# see if tick_iterator method can be simplified by reusing the parent method.
97

8+
import functools
9+
1010
import numpy as np
1111

12+
import matplotlib.patches as mpatches
13+
from matplotlib.path import Path
1214
from matplotlib.transforms import IdentityTransform
13-
from . import grid_helper_curvelinear
15+
import matplotlib.axes as maxes
16+
17+
from mpl_toolkits.axes_grid1.parasite_axes import host_axes_class_factory
18+
19+
from . import axislines, grid_helper_curvelinear
1420
from .axis_artist import AxisArtist
21+
from .grid_finder import ExtremeFinderSimple
1522

1623

17-
class FloatingAxisArtistHelper(grid_helper_curvelinear.FloatingAxisArtistHelper):
24+
class FloatingAxisArtistHelper(
25+
grid_helper_curvelinear.FloatingAxisArtistHelper):
1826
pass
1927

2028

@@ -25,8 +33,7 @@ def __init__(self, grid_helper, side, nth_coord_ticks=None):
2533
nth_coord = along which coordinate value varies.
2634
nth_coord = 0 -> x axis, nth_coord = 1 -> y axis
2735
"""
28-
29-
value, nth_coord = grid_helper.get_data_boundary(side) # return v= 0 , nth=1, extremes of the other coordinate.
36+
value, nth_coord = grid_helper.get_data_boundary(side)
3037
super().__init__(grid_helper, nth_coord, value, axis_direction=side)
3138
if nth_coord_ticks is None:
3239
nth_coord_ticks = nth_coord
@@ -117,9 +124,9 @@ def transform_xy(x, y):
117124
labels = [l for l, m in zip(labels, mask) if m]
118125

119126
def f1():
120-
dd = np.arctan2(yy1b-yy1a, xx1b-xx1a) # angle normal
121-
dd2 = np.arctan2(yy2b-yy2a, xx2b-xx2a) # angle tangent
122-
mm = ((yy1b-yy1a)==0.) & ((xx1b-xx1a)==0.) # mask where dd1 is not defined
127+
dd = np.arctan2(yy1b - yy1a, xx1b - xx1a) # angle normal
128+
dd2 = np.arctan2(yy2b - yy2a, xx2b - xx2a) # angle tangent
129+
mm = (yy1b - yy1a == 0) & (xx1b - xx1a == 0) # mask not defined dd
123130
dd[mm] = dd2[mm] + np.pi / 2
124131

125132
trans_tick = self.get_tick_transform(axes)
@@ -134,21 +141,15 @@ def f1():
134141
return f1(), iter([])
135142

136143
def get_line(self, axes):
137-
138144
self.update_lim(axes)
139-
from matplotlib.path import Path
140145
k, v = dict(left=("lon_lines0", 0),
141146
right=("lon_lines0", 1),
142147
bottom=(" EDBE lat_lines0", 0),
143148
top=("lat_lines0", 1))[self._side]
144-
145149
xx, yy = self.grid_info[k][v]
146150
return Path(np.column_stack([xx, yy]))
147151

148152

149-
from .grid_finder import ExtremeFinderSimple
150-
151-
152153
class ExtremeFinderFixed(ExtremeFinderSimple):
153154
def __init__(self, extremes):
154155
self._extremes = extremes
@@ -160,7 +161,6 @@ def __call__(self, transform_xy, x1, y1, x2, y2):
160161
x1, y1, x2, y2 in image coordinates (0-based)
161162
nx, ny : number of division in each axis
162163
"""
163-
#lon_min, lon_max, lat_min, lat_max = self._extremes
164164
return self._extremes
165165

166166

@@ -183,7 +183,7 @@ def __init__(self, aux_trans, extremes,
183183

184184
def get_data_boundary(self, side):
185185
"""
186-
return v= 0 , nth=1
186+
return v=0, nth=1
187187
"""
188188
lon1, lon2, lat1, lat2 = self._extremes
189189
return dict(left=(lon1, 0),
@@ -269,20 +269,17 @@ def _update_grid(self, x1, y1, x2, y2):
269269
else:
270270
lat_values = np.asarray(lat_levs[:lat_n]/lat_factor)
271271

272-
lon_values0 = lon_values[(lon_min<lon_values) & (lon_values<lon_max)]
273-
lat_values0 = lat_values[(lat_min<lat_values) & (lat_values<lat_max)]
274-
lon_lines, lat_lines = grid_finder._get_raw_grid_lines(lon_values0,
275-
lat_values0,
276-
lon_min, lon_max,
277-
lat_min, lat_max)
272+
lon_lines, lat_lines = grid_finder._get_raw_grid_lines(
273+
lon_values[(lon_min < lon_values) & (lon_values < lon_max)],
274+
lat_values[(lat_min < lat_values) & (lat_values < lat_max)],
275+
lon_min, lon_max, lat_min, lat_max)
278276

279277
grid_info["lon_lines"] = lon_lines
280278
grid_info["lat_lines"] = lat_lines
281279

282-
lon_lines, lat_lines = grid_finder._get_raw_grid_lines(extremes[:2],
283-
extremes[2:],
284-
*extremes)
285-
# lon_min, lon_max, lat_min, lat_max)
280+
lon_lines, lat_lines = grid_finder._get_raw_grid_lines(
281+
extremes[:2], extremes[2:], *extremes)
282+
# lon_min, lon_max, lat_min, lat_max)
286283

287284
grid_info["lon_lines0"] = lon_lines
288285
grid_info["lat_lines0"] = lat_lines
@@ -344,7 +341,6 @@ def _gen_axes_patch(self):
344341
.. note::
345342
Intended to be overridden by new projection types.
346343
"""
347-
import matplotlib.patches as mpatches
348344
grid_helper = self.get_grid_helper()
349345
t = grid_helper.get_boundary()
350346
return mpatches.Polygon(t)
@@ -386,11 +382,6 @@ def floatingaxes_class_factory(axes_class):
386382
{'_axes_class_floating': axes_class})
387383

388384

389-
from .axislines import Axes
390-
from mpl_toolkits.axes_grid1.parasite_axes import host_axes_class_factory
391-
392-
FloatingAxes = floatingaxes_class_factory(host_axes_class_factory(Axes))
393-
394-
395-
import matplotlib.axes as maxes
385+
FloatingAxes = floatingaxes_class_factory(
386+
host_axes_class_factory(axislines.Axes))
396387
FloatingSubplot = maxes.subplot_class_factory(FloatingAxes)

0 commit comments

Comments
 (0)
0