I want to make markersize
equal to a single unit in height. It seems that markersize
is in pixels. How can I get at how large "1 unit" (along a given axis) is, in pixels?
The native figure size unit in Matplotlib is inches, deriving from print industry standards. However, users may need to specify their figures in other units like centimeters or pixels.
BboxTransformTo is a transformation that linearly transforms points from the unit bounding box to a given Bbox. In your case, the transform itself is based upon a TransformedBBox which again has a Bbox upon which it is based and a transform - for this nested instance an Affine2D transform.
Have a look at the Transformations tutorial (wow, that took a lot of digging to find -- !)
In particular, axes.transData.transform(points)
returns pixel coordinates where (0,0) is the bottom-left of the viewport.
import matplotlib.pyplot as plt
# set up a figure
fig = plt.figure()
ax = fig.add_subplot(111)
x = np.arange(0, 10, 0.005)
y = np.exp(-x/2.) * np.sin(2*np.pi*x)
ax.plot(x,y)
# what's one vertical unit & one horizontal unit in pixels?
ax.transData.transform([(0,1),(1,0)])-ax.transData.transform((0,0))
# Returns:
# array([[ 0., 384.], <-- one y unit is 384 pixels (on my computer)
# [ 496., 0.]]) <-- one x unit is 496 pixels.
There are various other transforms you can do -- coordinates relative to your data, relative to the axes, as a proportion of the figure, or in pixels for the figure (the transformations tutorial is really good).
TO convert between pixels and points (a point is 1/72 inches), you may be able to play around with matplotlib.transforms.ScaledTransform
and fig.dpi_scale_trans
(the tutorial has something on this, I think).
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With