x y scale bar
k1moradi opened this issue · 7 comments
Hi,
I was wondering is it possible to add two scale bars: one for the x-axis and another one for the y-axis. The x-axis of my plot is in milliseconds and the y-axis in pico ampers.
I have generated the following plot but, I want the unit of the plot being "ms" which the program does not allow. I also want to add another scalebar for the y-axis, so that I can hide the axis.
scalebar = ScaleBar(1, label='ms', location='lower right')
plt.gca().add_artist(scalebar)
Hi, two-part answer. First, you can have as many scalebars as you want in a figure, but currently there is no way to draw a vertical scale bar. I will try to see whether this can be added to the library. Secondly, millisecond (or the base units second) is not a known "length" dimension so you need to define your own Dimension class.
import matplotlib.pyplot as plt
from matplotlib_scalebar.scalebar import ScaleBar
from matplotlib_scalebar.dimension import _Dimension, _PREFIXES_FACTORS, _LATEX_MU
class TimeDimension(_Dimension):
def __init__(self):
super().__init__("s")
for prefix, factor in _PREFIXES_FACTORS.items():
latexrepr = None
if prefix == "\u00b5" or prefix == "u":
latexrepr = _LATEX_MU + "s"
self.add_units(prefix + "s", factor, latexrepr)
plt.figure()
plt.gca().add_artist(
ScaleBar(5, units="ms", dimension=TimeDimension(), location="lower right")
)
plt.savefig("example_dimension.png")
Thanks for the suggestions!
I will try to see whether this can be added to the library.
I hope everything works out since I still need this feature.
Not sure if it helps but this AnchoredScaleBar
from @dmeliza adds a vertical component
https://gist.github.com/dmeliza/3251476
Haven't figured out the logic for rotation myself -- I need something similar
Not sure if it helps but this
AnchoredScaleBar
from @dmeliza adds a vertical componenthttps://gist.github.com/dmeliza/3251476
Haven't figured out the logic for rotation myself -- I need something similar
Thanks for letting me know about this! It works.
I just merged some changes to allow a "vertical" scale bar. See help documentation: https://github.com/ppinard/matplotlib-scalebar#rotation. I will release a new version of matplotlib-scalebar to PyPI in the coming week.
I just merged some changes to allow a "vertical" scale bar. See help documentation: https://github.com/ppinard/matplotlib-scalebar#rotation. I will release a new version of matplotlib-scalebar to PyPI in the coming week.
Thank you for the update and happy new year!
Now in release 0.7.0. Please close the issue if the solution works for you. Happy new year as well!