Skip to content

Commit e754928

Browse files
fneumFabianHofmann
andcommitted
plot: compute boundaries in all case for consistent circle sizes
Co-authored-by: FabianHofmann <hofmann@fias.uni-frankfurt.de>
1 parent bca3530 commit e754928

File tree

1 file changed

+15
-6
lines changed

1 file changed

+15
-6
lines changed

pypsa/plot.py

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@
5252

5353
def plot(
5454
n,
55-
margin=None,
55+
margin=0.05,
5656
ax=None,
5757
geomap=True,
5858
projection=None,
@@ -83,8 +83,9 @@ def plot(
8383
8484
Parameters
8585
----------
86-
margin : float
86+
margin : float, defaults to 0.05
8787
Margin at the sides as proportion of distance between max/min x,y
88+
Will be ignored if boundaries are given.
8889
ax : matplotlib ax, defaults to plt.gca()
8990
Axis to which to plot the network
9091
geomap: bool/str, default True
@@ -160,8 +161,17 @@ def plot(
160161
bus_collection, branch_collection1, ... : tuple of Collections
161162
Collections for buses and branches.
162163
"""
164+
165+
if margin is None:
166+
logger.warning(
167+
"The `margin` argument does support None value anymore. "
168+
"Falling back to the default value 0.05. This will raise "
169+
"an error in the future."
170+
)
171+
margin = 0.05
172+
163173
x, y = _get_coordinates(n, layouter=layouter)
164-
if boundaries is None and margin:
174+
if boundaries is None:
165175
boundaries = sum(zip(*compute_bbox_with_margins(margin, x, y)), ())
166176

167177
if geomap and not cartopy_present:
@@ -197,6 +207,8 @@ def plot(
197207
ax.set_extent(boundaries, crs=transform)
198208
elif ax is None:
199209
ax = plt.gca()
210+
elif hasattr(ax, "projection"):
211+
raise ValueError("Axis is a geo axis, but `geomap` is set to False")
200212
if not geomap and boundaries:
201213
ax.axis(boundaries)
202214

@@ -388,9 +400,6 @@ def plot(
388400
b_collection.set_zorder(3)
389401
branch_collections.append(b_collection)
390402

391-
if boundaries is None:
392-
ax.autoscale()
393-
394403
return (bus_collection,) + tuple(branch_collections) + tuple(arrow_collections)
395404

396405

0 commit comments

Comments
 (0)