Registry / data / matplotlib-scalebar

matplotlib-scalebar

JSON →
library0.9.0pypypi✓ verified 85d ago

Artist for matplotlib to display a scale bar. Current version: 0.9.0. Release cadence: infrequent, couple of years.

pip install matplotlib-scalebar
INSTALL
IMPORT
SIG · MATPLOTLIB-SCALEBA
M
matplotlib-scalebar
datapythonv0.9.0
Install
7.4s avg
Import
1893ms
Disk
181MB
Pass rate
10/ 10
Env Coverage10 / 10
glibc
3.93.13
musl
3.93.13
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
musl
py 3.103.95 runs
installs and imports cleanly · install 0.0s · import 1.940s · 177.6MB
glibc
py 3.103.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()
Debug
Known issues
breakingScaleBar no longer automatically rescales when axis limits change (fixed scale factor). Prior to 0.6.0 it auto-rescaled; now you must call scalebar.update() if you change limits after adding.
fix
Use scalebar.update() or recreate the ScaleBar after setting axis limits.
affects: >=0.6.0
gotchaThe unit string is not validated; if you pass an unknown unit like 'myunit', it will be displayed as-is. No error is raised.
fix
Use known units: 'm', 'cm', 'mm', 'um', 'nm', 'ft', 'in', etc.
affects: all
gotchaScaleBar uses the axes' x-axis data coordinates. If your data is not in physical units, the scale bar will be meaningless. Ensure you provide the correct calibration factor (dx) matching your data coordinates.
fix
Set dx to the length represented by one data unit in your desired physical unit.
affects: all
Errors
Common errors & fixes
ImportError: cannot import name 'ScaleBar' from 'scalebar'
Wrong import path. The package name is matplotlib_scalebar, not scalebar.
fix
Use: 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.
fix
Modify 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.
fix
Use loc='lower right' instead of location='lower right'.
Upgrade
Version history
0.9.0latest on PyPI · released Jan 17, 2025
Audit
Dependencies
matplotlibrequiredcore dependency
Agent activity
2 hits · last 30 days
node
2
Resources
matplotlib-scalebar — pip install matplotlib-scalebar · libregistry