Install & Compatibility
Where this runs
tested against v0.9.0 · pip install
no network on importno background threads
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
muslpy 3.10–3.95 runs
installs and imports cleanly · install 0.0s · import 1.940s · 177.6MB
glibcpy 3.10–3.95 runs
installs and imports cleanly · install 7.4s · import 1.846s · 170MB
181MB installed
● package 181MB
Code
Verified usage
Verified import paths — ran on the pinned version, not inferred.
ScaleBar
✓ from matplotlib_scalebar.scalebar import ScaleBar
✗ from scalebar import ScaleBar
module is matplotlib_scalebar, not scalebar
Basic usage: create a ScaleBar with calibration factor (dx) and unit, then add to axes.
import matplotlib.pyplot as plt
from matplotlib_scalebar.scalebar import ScaleBar
import numpy as np
# Create sample data
x = np.linspace(0, 10, 100)
y = np.sin(x)
fig, ax = plt.subplots()
ax.plot(x, y)
ax.set_xlabel('Distance (μm)')
# Add a scale bar: dx=1 means one unit in data coordinates = 1 μm
scalebar = ScaleBar(1, 'um', length_fraction=0.25)
ax.add_artist(scalebar)
plt.show()
Errors
Common errors & fixes
ImportError: cannot import name 'ScaleBar' from 'scalebar'
Wrong import path. The package name is matplotlib_scalebar, not scalebar.
fixUse: from matplotlib_scalebar.scalebar import ScaleBar
AttributeError: 'ScaleBar' object has no attribute 'set_font_properties'
You may be trying to set font properties on ScaleBar, which does not expose that directly. The text properties are internal.
fixModify the text via scalebar.text_props dict or by recreating the artist.
TypeError: __init__() got an unexpected keyword argument 'location'
The location parameter was renamed to 'loc' in version 0.8.0.
fixUse loc='lower right' instead of location='lower right'.
Upgrade
Version history
0.9.0latest on PyPI · released Jan 17, 2025
Audit
Dependencies
matplotlibrequiredcore dependency