Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/matlab/14.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 如何在matplotlib中获取轴上单个单位的长度(以像素为单位)?_Python_Matlab_Plot_Matplotlib - Fatal编程技术网

Python 如何在matplotlib中获取轴上单个单位的长度(以像素为单位)?

Python 如何在matplotlib中获取轴上单个单位的长度(以像素为单位)?,python,matlab,plot,matplotlib,Python,Matlab,Plot,Matplotlib,我想使它的高度等于一个单位。似乎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.aran

我想使它的高度等于一个单位。似乎
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.
导入matplotlib.pyplot作为plt
#树立形象
图=plt.图()
ax=图添加_子批次(111)
x=np.arange(0,10,0.005)
y=np.exp(-x/2.)*np.sin(2*np.pi*x)
轴图(x,y)
#以像素为单位的一个垂直单位和一个水平单位是什么?
ax.transData.transform([(0,1)、(1,0)])-ax.transData.transform((0,0))
#返回:

#数组([[0,384.],类似,但不是的副本:您可能会发现这很有用。