Skip to content

Fix scalebar rendering issue with multiple axes - #654

Open
DavidVadnais wants to merge 1 commit into
matplotlib:developfrom
DavidVadnais:fix/drawmapscale-ax-368
Open

Fix scalebar rendering issue with multiple axes#654
DavidVadnais wants to merge 1 commit into
matplotlib:developfrom
DavidVadnais:fix/drawmapscale-ax-368

Conversation

@DavidVadnais

Copy link
Copy Markdown

Fixes: #368

when a figure has more than one axes and drawmapscale(ax=ax0,...) is called while other axes (ax1) is up, scalebar is split

I have a test case for this but ill i try to narrow it down more. currently:

import matplotlib; matplotlib.use('Agg')
import matplotlib.pyplot as plt
from mpl_toolkits.basemap import Basemap

fig = plt.figure()
ax0 = fig.add_axes([0, 0, 1, 1])
fig.add_axes([.6, .6, .2, .2])  # becomes the "current" axes

m = Basemap(projection='lcc', width=3e6, height=3e6,
            lat_1=50, lat_0=47, lon_0=1, resolution=None)
rets = m.drawmapscale(-15, 47, -15, 47, 400, barstyle='fancy', ax=ax0)

bad = sum(r.axes is not ax0 for r in rets)
print(f"{bad}/{len(rets)} artists NOT on ax0") # if more then 0/N this is a failure.

…called while other axes (ax1) is up, scalebar is split
@DavidVadnais

DavidVadnais commented Sep 1, 2026

Copy link
Copy Markdown
Author

code from issue to see bug:

import pylab as pl
from mpl_toolkits.basemap import Basemap
m = Basemap(width=3000e3,height=3000e3,resolution='l',
         projection='lcc',lat_1=50.,lat_0=47,lon_0=1.)

ax0=pl.axes()
ax1=pl.axes([.6,.5,.15,.15], facecolor='#ddeeff')
ax1.set_title('ax1 (should stay empty)', fontsize=7)
m.drawcoastlines(ax=ax0)
lon,lat=-15,47
lon0,lat0=lon,lat
scaleL=400
#pl.axes(ax0) #this will avoid the problem...
o=m.drawmapscale(ax=ax0,lon=lon,lat=lat,lon0=lon0,lat0=lat0,
                   length=scaleL,barstyle='fancy',fontcolor='r')

pl.show()

Before:

image

After:

image

@DavidVadnais
DavidVadnais marked this pull request as ready for review September 1, 2026 00:25
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

small bug in drawmapscale

1 participant