我想把markersize
设置为高度单位为1。看起来markersize
是以像素为单位的。我怎样才能知道在像素中“1个单位”(沿给定轴线)有多大?
我想把markersize
设置为高度单位为1。看起来markersize
是以像素为单位的。我怎样才能知道在像素中“1个单位”(沿给定轴线)有多大?
axes.transData.transform(points)
返回像素坐标,其中(0,0)是视口左下角。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.
你可以进行各种其他的变换 -- 相对于数据,相对于轴,相对于图形的比例或以图形中的像素为单位(转换教程非常好)。
要在像素和点之间进行转换(1点=1/72英寸),您可以尝试使用matplotlib.transforms.ScaledTransform
和fig.dpi_scale_trans
(教程上可能有相关内容)。