matplotlib-map-utils 3.0.1__py3-none-any.whl → 3.1.0__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -46,6 +46,7 @@ class InsetMap(matplotlib.artist.Artist):
46
46
  coords: imt._TYPE_INSET["coords"]=None,
47
47
  transform=None,
48
48
  to_plot=None,
49
+ zorder: int=99,
49
50
  **kwargs):
50
51
  # Starting up the object with the base properties of a matplotlib Artist
51
52
  matplotlib.artist.Artist.__init__(self)
@@ -56,6 +57,7 @@ class InsetMap(matplotlib.artist.Artist):
56
57
  self._pad = imf._validate(imt._VALIDATE_INSET, "pad", pad)
57
58
  self._coords = imf._validate(imt._VALIDATE_INSET, "coords", coords)
58
59
  self._to_plot = imf._validate(imt._VALIDATE_INSET, "to_plot", to_plot)
60
+ self._zorder = imf._validate(imt._VALIDATE_INSET, "zorder", zorder)
59
61
 
60
62
  # Checking if we need to override values for size and pad
61
63
  if self._size is None:
@@ -65,11 +67,6 @@ class InsetMap(matplotlib.artist.Artist):
65
67
 
66
68
  self._transform = transform # not validated!
67
69
  self._kwargs = kwargs # not validated!
68
-
69
- # We do set the zorder for our objects individually,
70
- # but we ALSO set it for the entire artist, here
71
- # Thank you to matplotlib-scalebar for this tip
72
- zorder = 99
73
70
 
74
71
  ## INTERNAL PROPERTIES ##
75
72
  # This allows for easy-updating of properties
@@ -162,6 +159,16 @@ class InsetMap(matplotlib.artist.Artist):
162
159
  def to_plot(self, val):
163
160
  val = imf._validate(imt._VALIDATE_INSET, "to_plot", val)
164
161
  self._to_plot = val
162
+
163
+ # zorder
164
+ @property
165
+ def zorder(self):
166
+ return self._zorder
167
+
168
+ @zorder.setter
169
+ def zorder(self, val):
170
+ val = imf._validate(imt._VALIDATE_INSET, "zorder", val)
171
+ self._zorder = val
165
172
 
166
173
  ## COPY FUNCTION ##
167
174
  # This is solely to get around matplotlib's restrictions around re-using an artist across multiple axes
@@ -176,7 +183,7 @@ class InsetMap(matplotlib.artist.Artist):
176
183
  def create(self, pax, **kwargs):
177
184
  # Can re-use the drawing function we already established, but return the object instead
178
185
  iax = inset_map(ax=pax, location=self._location, size=self._size,
179
- pad=self._pad, coords=self._coords, transform=self._transform,
186
+ pad=self._pad, coords=self._coords, transform=self._transform, zorder=self._zorder,
180
187
  **self._kwargs, **kwargs)
181
188
 
182
189
  # If data is passed to to_plot, then we plot that on the newly created axis as well
@@ -226,6 +233,7 @@ class ExtentIndicator(matplotlib.artist.Artist):
226
233
  linecolor: imt._TYPE_EXTENT["linecolor"]="red",
227
234
  alpha: imt._TYPE_EXTENT["alpha"]=0.5,
228
235
  linewidth: imt._TYPE_EXTENT["linewidth"]=1,
236
+ zorder: int=99,
229
237
  **kwargs):
230
238
  # Starting up the object with the base properties of a matplotlib Artist
231
239
  matplotlib.artist.Artist.__init__(self)
@@ -239,13 +247,9 @@ class ExtentIndicator(matplotlib.artist.Artist):
239
247
  self._linecolor = imf._validate(imt._VALIDATE_EXTENT, "linecolor", linecolor)
240
248
  self._alpha = imf._validate(imt._VALIDATE_EXTENT, "alpha", alpha)
241
249
  self._linewidth = imf._validate(imt._VALIDATE_EXTENT, "linewidth", linewidth)
250
+ self._zorder = imf._validate(imt._VALIDATE_EXTENT, "zorder", zorder)
242
251
 
243
252
  self._kwargs = kwargs # not validated!
244
-
245
- # We do set the zorder for our objects individually,
246
- # but we ALSO set it for the entire artist, here
247
- # Thank you to matplotlib-scalebar for this tip
248
- zorder = 99
249
253
 
250
254
  ## INTERNAL PROPERTIES ##
251
255
  # This allows for easy-updating of properties
@@ -332,6 +336,16 @@ class ExtentIndicator(matplotlib.artist.Artist):
332
336
  def linewidth(self, val):
333
337
  val = imf._validate(imt._VALIDATE_EXTENT, "linewidth", val)
334
338
  self._linewidth = val
339
+
340
+ # zorder
341
+ @property
342
+ def zorder(self):
343
+ return self._zorder
344
+
345
+ @zorder.setter
346
+ def zorder(self, val):
347
+ val = imf._validate(imt._VALIDATE_EXTENT, "zorder", val)
348
+ self._zorder = val
335
349
 
336
350
  # kwargs
337
351
  @property
@@ -366,7 +380,7 @@ class ExtentIndicator(matplotlib.artist.Artist):
366
380
  to_return=self._to_return, straighten=self._straighten,
367
381
  pad=self._pad, plot=self._plot,
368
382
  facecolor=self._facecolor, linecolor=self._linecolor,
369
- alpha=self._alpha, linewidth=self._linewidth,
383
+ alpha=self._alpha, linewidth=self._linewidth, zorder=self._zorder,
370
384
  **self._kwargs, **kwargs)
371
385
 
372
386
  # The indicator will be drawn automatically if plot is True
@@ -389,6 +403,7 @@ class DetailIndicator(matplotlib.artist.Artist):
389
403
  linewidth: imt._TYPE_EXTENT["linewidth"]=1,
390
404
  connector_color: imt._TYPE_DETAIL["connector_color"]="black",
391
405
  connector_width: imt._TYPE_DETAIL["connector_width"]=1,
406
+ zorder: int=99,
392
407
  **kwargs):
393
408
  # Starting up the object with the base properties of a matplotlib Artist
394
409
  matplotlib.artist.Artist.__init__(self)
@@ -404,13 +419,9 @@ class DetailIndicator(matplotlib.artist.Artist):
404
419
  self._to_return = imf._validate(imt._VALIDATE_DETAIL, "to_return", to_return)
405
420
  self._connector_color = imf._validate(imt._VALIDATE_DETAIL, "connector_color", connector_color)
406
421
  self._connector_width = imf._validate(imt._VALIDATE_DETAIL, "connector_width", connector_width)
422
+ self._zorder = imf._validate(imt._VALIDATE_DETAIL, "zorder", zorder)
407
423
 
408
424
  self._kwargs = kwargs # not validated!
409
-
410
- # We do set the zorder for our objects individually,
411
- # but we ALSO set it for the entire artist, here
412
- # Thank you to matplotlib-scalebar for this tip
413
- zorder = 99
414
425
 
415
426
  ## INTERNAL PROPERTIES ##
416
427
  # This allows for easy-updating of properties
@@ -517,6 +528,16 @@ class DetailIndicator(matplotlib.artist.Artist):
517
528
  def connector_width(self, val):
518
529
  val = imf._validate(imt._VALIDATE_DETAIL, "connector_width", val)
519
530
  self._connector_width = val
531
+
532
+ # zorder
533
+ @property
534
+ def zorder(self):
535
+ return self._zorder
536
+
537
+ @zorder.setter
538
+ def zorder(self, val):
539
+ val = imf._validate(imt._VALIDATE_DETAIL, "zorder", val)
540
+ self._zorder = val
520
541
 
521
542
  # kwargs
522
543
  @property
@@ -544,7 +565,8 @@ class DetailIndicator(matplotlib.artist.Artist):
544
565
  pax: imt._TYPE_EXTENT["pax"],
545
566
  iax: imt._TYPE_EXTENT["bax"],
546
567
  pcrs: imt._TYPE_EXTENT["pcrs"],
547
- icrs: imt._TYPE_EXTENT["bcrs"], **kwargs):
568
+ icrs: imt._TYPE_EXTENT["bcrs"],
569
+ **kwargs):
548
570
 
549
571
  # Can re-use the drawing function we already established, but return the object instead
550
572
  dti = indicate_detail(pax=pax, iax=iax, pcrs=pcrs, icrs=icrs,
@@ -554,6 +576,7 @@ class DetailIndicator(matplotlib.artist.Artist):
554
576
  alpha=self._alpha, linewidth=self._linewidth,
555
577
  connector_color=self._connector_color,
556
578
  connector_width=self._connector_width,
579
+ zorder=self._zorder,
557
580
  **self._kwargs, **kwargs)
558
581
 
559
582
  # The indicator will be drawn automatically if plot is True
@@ -573,6 +596,7 @@ def inset_map(ax,
573
596
  pad: imt._TYPE_INSET["pad"]=None,
574
597
  coords: imt._TYPE_INSET["coords"]=None,
575
598
  transform=None,
599
+ zorder: int=99,
576
600
  **kwargs):
577
601
 
578
602
  ## VALIDATION ##
@@ -580,6 +604,7 @@ def inset_map(ax,
580
604
  size = imf._validate(imt._VALIDATE_INSET, "size", size)
581
605
  pad = imf._validate(imt._VALIDATE_INSET, "pad", pad)
582
606
  coords = imf._validate(imt._VALIDATE_INSET, "coords", coords)
607
+ zorder = imf._validate(imt._VALIDATE_INSET, "zorder", zorder)
583
608
 
584
609
  if size is None:
585
610
  size = _DEFAULT_INSET_MAP["size"]
@@ -671,7 +696,7 @@ def inset_map(ax,
671
696
  ## DRAWING ##
672
697
  # Creating the new inset map with the specified height, width, and location
673
698
  # by default, inset_axes requires everything to be in ax.transAxes coordinates
674
- iax = ax.inset_axes([x, y, inset_width, inset_height], **kwargs)
699
+ iax = ax.inset_axes([x, y, inset_width, inset_height], zorder=zorder, **kwargs)
675
700
 
676
701
  # We also set the anchor here, such that it stays fixed when any resizing takes place
677
702
  loc_anchors = {
@@ -701,6 +726,7 @@ def indicate_extent(pax: imt._TYPE_EXTENT["pax"],
701
726
  linecolor: imt._TYPE_EXTENT["linecolor"]="red",
702
727
  alpha: imt._TYPE_EXTENT["alpha"]=0.5,
703
728
  linewidth: imt._TYPE_EXTENT["linewidth"]=1,
729
+ zorder: int=99,
704
730
  **kwargs):
705
731
 
706
732
  ## VALIDATION ##
@@ -716,6 +742,7 @@ def indicate_extent(pax: imt._TYPE_EXTENT["pax"],
716
742
  linecolor = imf._validate(imt._VALIDATE_EXTENT, "linecolor", linecolor)
717
743
  alpha = imf._validate(imt._VALIDATE_EXTENT, "alpha", alpha)
718
744
  linewidth = imf._validate(imt._VALIDATE_EXTENT, "linewidth", linewidth)
745
+ zorder = imf._validate(imt._VALIDATE_EXTENT, "zorder", zorder)
719
746
 
720
747
  # Make sure the figure layout is calculated
721
748
  fig = pax.get_figure()
@@ -748,15 +775,13 @@ def indicate_extent(pax: imt._TYPE_EXTENT["pax"],
748
775
  # Straightening the points if desired
749
776
  if straighten == True:
750
777
  extent_shape = shapely.envelope(extent_shape)
751
-
752
- # return extent_shape
753
-
778
+
754
779
  # Plotting, if desired
755
780
  if plot == True:
756
781
  # Note that the alpha ONLY applies to the facecolor!
757
782
  extent_patch = matplotlib.patches.Polygon(list(extent_shape.exterior.coords), transform=pax.transData,
758
783
  facecolor=matplotlib.colors.to_rgba(facecolor, alpha=alpha),
759
- edgecolor=linecolor, linewidth=linewidth, **kwargs)
784
+ edgecolor=linecolor, linewidth=linewidth, zorder=zorder, **kwargs)
760
785
  pax.add_artist(extent_patch)
761
786
 
762
787
  # Deciding what we need to return
@@ -789,8 +814,7 @@ def indicate_detail(pax: imt._TYPE_EXTENT["pax"],
789
814
  alpha: imt._TYPE_EXTENT["alpha"]=1,
790
815
  linecolor: imt._TYPE_EXTENT["linecolor"]="black",
791
816
  linewidth: imt._TYPE_EXTENT["linewidth"]=1,
792
- # connector_color: imt._TYPE_DETAIL["connector_color"]="black",
793
- # connector_width: imt._TYPE_DETAIL["connector_width"]=1,
817
+ zorder: int=99,
794
818
  **kwargs):
795
819
 
796
820
  fig = pax.get_figure()
@@ -809,8 +833,7 @@ def indicate_detail(pax: imt._TYPE_EXTENT["pax"],
809
833
  alpha = imf._validate(imt._VALIDATE_EXTENT, "alpha", alpha)
810
834
  linecolor = imf._validate(imt._VALIDATE_EXTENT, "linecolor", linecolor)
811
835
  linewidth = imf._validate(imt._VALIDATE_EXTENT, "linewidth", linewidth)
812
- # connector_color = imf._validate(imt._VALIDATE_DETAIL, "connector_color", connector_color)
813
- # connector_width = imf._validate(imt._VALIDATE_DETAIL, "connector_width", connector_width)
836
+ zorder = imf._validate(imt._VALIDATE_EXTENT, "zorder", zorder)
814
837
 
815
838
  # Drawing the extent indicator on the main map
816
839
  # Setting to_return="ax" gets us the corners of the patch in pax.transAxes coordinates
@@ -819,7 +842,7 @@ def indicate_detail(pax: imt._TYPE_EXTENT["pax"],
819
842
  straighten=straighten, pad=pad, plot=plot,
820
843
  facecolor=facecolor, linecolor=linecolor,
821
844
  alpha=alpha, linewidth=linewidth*1.25,
822
- to_return="ax", **kwargs)[:4]
845
+ to_return="ax", zorder=zorder, **kwargs)[:4]
823
846
 
824
847
  # Getting the inset axis points and transforming them to the parent axis CRS
825
848
  corners_inset = _inset_corners_to_parent(pax, iax)
@@ -873,12 +896,13 @@ def indicate_detail(pax: imt._TYPE_EXTENT["pax"],
873
896
  for c in connections:
874
897
  # This is listed as [extent_x, inset_x], [extent_y, inset_y]
875
898
  pax.plot([c[0][0], c[1][0]], [c[0][1], c[1][1]],
876
- color=linecolor, linewidth=linewidth, transform=pax.transAxes)
899
+ color=linecolor, linewidth=linewidth, transform=pax.transAxes, zorder=zorder+1)
877
900
 
878
- # Also updating the linewidth and color of the inset map itsef, to match
879
- for a in ["top","bottom","left","right"]:
880
- iax.spines[a].set_linewidth(linewidth*1.2) # making this slightly thicker
881
- iax.spines[a].set_edgecolor(linecolor)
901
+ # Also updating the linewidth and color of the inset map itself, to match
902
+ iax.spines[:].set_linewidth(linewidth*1.2) # making this slightly thicker
903
+ iax.spines[:].set_edgecolor(linecolor)
904
+ iax.set_zorder(zorder+2)
905
+ iax.spines[:].set_zorder(zorder+2)
882
906
 
883
907
  # Returning as requested
884
908
  if to_return is None:
@@ -893,37 +917,37 @@ def indicate_detail(pax: imt._TYPE_EXTENT["pax"],
893
917
  # This is a top-level helping function
894
918
  # that will return an axis with inset maps drawn for Alaska, Hawaii, DC, and/or Puerto Rico
895
919
  # NOTE that as of this initial release, it assumes your map is in CRS 3857 for positioning
896
- def inset_usa(ax, alaska=True, hawaii=True, dc=True, puerto_rico=True, size=None, pad=None, **kwargs):
920
+ def inset_usa(ax, alaska=True, hawaii=True, dc=True, puerto_rico=True, size=None, pad=None, zorder: int=99, **kwargs):
897
921
  # This will return all of the axes we create
898
922
  to_return = []
899
923
 
900
924
  # Alaska and Hawaii are positioned relative to each other
901
925
  if alaska == True and hawaii == True:
902
- aax = inset_map(ax, "lower left", size, pad, **kwargs)
926
+ aax = inset_map(ax, "lower left", size, pad, zorder=zorder, **kwargs)
903
927
  to_return.append(aax)
904
928
  # Need to shift over the hawaii axis by the size of the alaska axis
905
929
  # Note that we add xmax and xmin together here, to account for the padding (xmin is the amount of padding)
906
930
  shift_right = float(aax.get_window_extent().transformed(ax.transAxes.inverted()).xmax) + float(aax.get_window_extent().transformed(ax.transAxes.inverted()).xmin)
907
931
  # also need to shift it up, by the amount of the padding (which we can crib from ymin)
908
932
  shift_up = float(aax.get_window_extent().transformed(ax.transAxes.inverted()).ymin)
909
- hax = inset_map(ax, "lower left", size, pad, coords=(shift_right, shift_up), **kwargs)
933
+ hax = inset_map(ax, "lower left", size, pad, zorder=zorder, coords=(shift_right, shift_up), **kwargs)
910
934
  to_return.append(hax)
911
935
  else:
912
936
  if alaska == True:
913
- aax = inset_map(ax, "lower_left", size, pad, **kwargs)
937
+ aax = inset_map(ax, "lower_left", size, pad, zorder=zorder, **kwargs)
914
938
  to_return.append(aax)
915
939
  if hawaii == True:
916
- hax = inset_map(ax, "lower left", size, pad, **kwargs)
940
+ hax = inset_map(ax, "lower left", size, pad, zorder=zorder, **kwargs)
917
941
  to_return.append(hax)
918
942
 
919
943
  # Puerto Rico is positioned off the coast of Florida
920
944
  if puerto_rico == True:
921
- pax = inset_map(ax, "lower right", size, pad, **kwargs)
945
+ pax = inset_map(ax, "lower right", size, pad, zorder=zorder, **kwargs)
922
946
  to_return.append(pax)
923
947
 
924
948
  # DC is off the coast of DC
925
949
  if dc == True:
926
- dax = inset_map(ax, "center right", size, pad, **kwargs)
950
+ dax = inset_map(ax, "center right", size, pad, zorder=zorder, **kwargs)
927
951
  to_return.append(dax)
928
952
 
929
953
  # Finally, returning everything
@@ -45,7 +45,8 @@ class NorthArrow(matplotlib.artist.Artist):
45
45
  scale: None | float | int=None,
46
46
  base: None | bool | nat._TYPE_BASE = None, fancy: None | bool | nat._TYPE_FANCY = None,
47
47
  label: None | bool | nat._TYPE_LABEL = None, shadow: None | bool | nat._TYPE_SHADOW = None,
48
- pack: None | nat._TYPE_PACK = None, aob: None | nat._TYPE_AOB = None, rotation: None | nat._TYPE_ROTATION = None):
48
+ pack: None | nat._TYPE_PACK = None, aob: None | nat._TYPE_AOB = None, rotation: None | nat._TYPE_ROTATION = None,
49
+ zorder: int=99,):
49
50
  # Starting up the object with the base properties of a matplotlib Artist
50
51
  matplotlib.artist.Artist.__init__(self)
51
52
 
@@ -57,6 +58,9 @@ class NorthArrow(matplotlib.artist.Artist):
57
58
  location = naf._validate(nat._VALIDATE_PRIMARY, "location", location)
58
59
  self._location = location
59
60
 
61
+ zorder = naf._validate(nat._VALIDATE_PRIMARY, "zorder", zorder)
62
+ self._zorder = zorder
63
+
60
64
  # Scale will set to the default size if no value is passed
61
65
  scale = naf._validate(nat._VALIDATE_PRIMARY, "scale", scale)
62
66
  if scale is None:
@@ -84,11 +88,6 @@ class NorthArrow(matplotlib.artist.Artist):
84
88
  self._aob = aob
85
89
  rotation = naf._validate_dict(rotation, _DEFAULT_ROTATION | rotation, nat._VALIDATE_ROTATION, return_clean=True, parse_false=False)
86
90
  self._rotation = rotation
87
-
88
- # We do set the zorder for our objects individually,
89
- # but we ALSO set it for the entire artist, here
90
- # Thank you to matplotlib-scalebar for this tip
91
- zorder = 99
92
91
 
93
92
  ## INTERNAL PROPERTIES ##
94
93
  # This allows for easy-updating of properties
@@ -204,6 +203,16 @@ class NorthArrow(matplotlib.artist.Artist):
204
203
  val = naf._validate_type("rotation", val, dict)
205
204
  val = naf._validate_dict(val, self._rotation, nat._VALIDATE_ROTATION, return_clean=True, parse_false=False)
206
205
  self._rotation = val
206
+
207
+ # zorder
208
+ @property
209
+ def zorder(self):
210
+ return self._zorder
211
+
212
+ @zorder.setter
213
+ def zorder(self, val: int):
214
+ val = naf._validate(nat._VALIDATE_PRIMARY, "zorder", val)
215
+ self._zorder = val
207
216
 
208
217
  ## COPY FUNCTION ##
209
218
  # This is solely to get around matplotlib's restrictions around re-using an artist across multiple axes
@@ -221,10 +230,12 @@ class NorthArrow(matplotlib.artist.Artist):
221
230
  na_artist = north_arrow(ax=self.axes, location=self._location, scale=self._scale, draw=False,
222
231
  base=self._base, fancy=self._fancy,
223
232
  label=self._label, shadow=self._shadow,
224
- pack=self._pack, aob=self._aob, rotation=self._rotation)
233
+ pack=self._pack, aob=self._aob, rotation=self._rotation,
234
+ zorder=self._zorder)
225
235
  # This handles the actual drawing
226
236
  na_artist.axes = self.axes
227
237
  na_artist.set_figure(self.axes.get_figure())
238
+ na_artist.set_zorder(self._zorder)
228
239
  na_artist.draw(renderer)
229
240
 
230
241
  ## SIZE FUNCTION ##
@@ -264,10 +275,12 @@ def north_arrow(ax, draw=True,
264
275
  shadow: None | bool | nat._TYPE_SHADOW=None,
265
276
  pack: None | nat._TYPE_PACK=None,
266
277
  aob: None | nat._TYPE_AOB=None,
267
- rotation: None | nat._TYPE_ROTATION=None):
278
+ rotation: None | nat._TYPE_ROTATION=None,
279
+ zorder: int=99,):
268
280
 
269
- # First, validating the two primary inputs
281
+ # First, validating the three primary inputs
270
282
  _location = naf._validate(nat._VALIDATE_PRIMARY, "location", location)
283
+ _zorder = naf._validate(nat._VALIDATE_PRIMARY, "zorder", zorder)
271
284
 
272
285
  if scale is None:
273
286
  _scale = _DEFAULT_SCALE
@@ -373,6 +386,8 @@ def north_arrow(ax, draw=True,
373
386
  rotate_deg = _rotation["degrees"]
374
387
  # Then, apply the rotation to the aob box
375
388
  _iterative_rotate(aob_box, rotate_deg)
389
+
390
+ aob_box.set_zorder(_zorder)
376
391
 
377
392
  ## DRAWING ##
378
393
  # If this option is set to true, we'll draw the final artists as desired