{"id":21557,"library":"matplotlib-scalebar","title":"matplotlib-scalebar","description":"Artist for matplotlib to display a scale bar. Current version: 0.9.0. Release cadence: infrequent, couple of years.","status":"active","version":"0.9.0","language":"python","source_language":"en","source_url":"https://github.com/ppinard/matplotlib-scalebar","tags":["matplotlib","scalebar","plotting","visualization","scientific"],"install":[{"cmd":"pip install matplotlib-scalebar","lang":"bash","label":"pip install"}],"dependencies":[{"reason":"core dependency","package":"matplotlib","optional":false}],"imports":[{"note":"module is matplotlib_scalebar, not scalebar","wrong":"from scalebar import ScaleBar","symbol":"ScaleBar","correct":"from matplotlib_scalebar.scalebar import ScaleBar"}],"quickstart":{"code":"import matplotlib.pyplot as plt\nfrom matplotlib_scalebar.scalebar import ScaleBar\nimport numpy as np\n\n# Create sample data\nx = np.linspace(0, 10, 100)\ny = np.sin(x)\n\nfig, ax = plt.subplots()\nax.plot(x, y)\nax.set_xlabel('Distance (μm)')\n\n# Add a scale bar: dx=1 means one unit in data coordinates = 1 μm\nscalebar = ScaleBar(1, 'um', length_fraction=0.25)\nax.add_artist(scalebar)\nplt.show()","lang":"python","description":"Basic usage: create a ScaleBar with calibration factor (dx) and unit, then add to axes."},"warnings":[{"fix":"Use scalebar.update() or recreate the ScaleBar after setting axis limits.","message":"ScaleBar 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.","severity":"breaking","affected_versions":">=0.6.0"},{"fix":"Use known units: 'm', 'cm', 'mm', 'um', 'nm', 'ft', 'in', etc.","message":"The unit string is not validated; if you pass an unknown unit like 'myunit', it will be displayed as-is. No error is raised.","severity":"gotcha","affected_versions":"all"},{"fix":"Set dx to the length represented by one data unit in your desired physical unit.","message":"ScaleBar 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.","severity":"gotcha","affected_versions":"all"}],"env_vars":null,"last_verified":"2026-04-27T00:00:00.000Z","next_check":"2026-07-26T00:00:00.000Z","problems":[{"fix":"Use: from matplotlib_scalebar.scalebar import ScaleBar","cause":"Wrong import path. The package name is matplotlib_scalebar, not scalebar.","error":"ImportError: cannot import name 'ScaleBar' from 'scalebar'"},{"fix":"Modify the text via scalebar.text_props dict or by recreating the artist.","cause":"You may be trying to set font properties on ScaleBar, which does not expose that directly. The text properties are internal.","error":"AttributeError: 'ScaleBar' object has no attribute 'set_font_properties'"},{"fix":"Use loc='lower right' instead of location='lower right'.","cause":"The location parameter was renamed to 'loc' in version 0.8.0.","error":"TypeError: __init__() got an unexpected keyword argument 'location'"}],"ecosystem":"pypi","meta_description":null,"install_score":null,"install_tag":null,"quickstart_score":null,"quickstart_tag":null}