Skip to content

Commit a6316f5

Browse files
committed
Make GeoAxes.set_{latitude,longitude}_grid clearer.
Do the calculation in degrees instead of trying to "optimize" the calculation in radians.
1 parent b86b9b9 commit a6316f5

File tree

2 files changed

+13
-17
lines changed

2 files changed

+13
-17
lines changed

examples/api/custom_projection_example.py

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -297,10 +297,9 @@ def set_longitude_grid(self, degrees):
297297
class -- it provides a more convenient interface to set the
298298
ticking than set_xticks would.
299299
"""
300-
number = int(360 / degrees) + 1
301-
self.xaxis.set_major_locator(
302-
FixedLocator(
303-
np.linspace(-np.pi, np.pi, number, True)[1:-1]))
300+
# Skip -180 and 180, which are the fixed limits.
301+
grid = np.arange(-180 + degrees, 180, degrees)
302+
self.xaxis.set_major_locator(FixedLocator(np.deg2rad(grid)))
304303
self.xaxis.set_major_formatter(self.ThetaFormatter(degrees))
305304

306305
def set_latitude_grid(self, degrees):
@@ -311,10 +310,9 @@ def set_latitude_grid(self, degrees):
311310
class -- it provides a more convenient interface than
312311
set_yticks would.
313312
"""
314-
number = int(180 / degrees) + 1
315-
self.yaxis.set_major_locator(
316-
FixedLocator(
317-
np.linspace(-np.pi / 2.0, np.pi / 2.0, number, True)[1:-1]))
313+
# Skip -90 and 90, which are the fixed limits.
314+
grid = np.arange(-90 + degrees, 90, degrees)
315+
self.yaxis.set_major_locator(FixedLocator(np.deg2rad(grid)))
318316
self.yaxis.set_major_formatter(self.ThetaFormatter(degrees))
319317

320318
def set_longitude_grid_ends(self, degrees):

lib/matplotlib/projections/geo.py

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -190,20 +190,18 @@ def set_longitude_grid(self, degrees):
190190
"""
191191
Set the number of degrees between each longitude grid.
192192
"""
193-
number = int(360 / degrees) + 1
194-
self.xaxis.set_major_locator(
195-
FixedLocator(
196-
np.linspace(-np.pi, np.pi, number, True)[1:-1]))
193+
# Skip -180 and 180, which are the fixed limits.
194+
grid = np.arange(-180 + degrees, 180, degrees)
195+
self.xaxis.set_major_locator(FixedLocator(np.deg2rad(grid)))
197196
self.xaxis.set_major_formatter(self.ThetaFormatter(degrees))
198197

199198
def set_latitude_grid(self, degrees):
200199
"""
201-
Set the number of degrees between each longitude grid.
200+
Set the number of degrees between each latitude grid.
202201
"""
203-
number = int(180 / degrees) + 1
204-
self.yaxis.set_major_locator(
205-
FixedLocator(
206-
np.linspace(-np.pi / 2.0, np.pi / 2.0, number, True)[1:-1]))
202+
# Skip -90 and 90, which are the fixed limits.
203+
grid = np.arange(-90 + degrees, 90, degrees)
204+
self.yaxis.set_major_locator(FixedLocator(np.deg2rad(grid)))
207205
self.yaxis.set_major_formatter(self.ThetaFormatter(degrees))
208206

209207
def set_longitude_grid_ends(self, degrees):

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy