matplot 坐标点_如何获取Matplotlib生成的散点图的像素坐标?

通过matplotlib的transformData方法,可以将散点图的x、y数据转换为像素坐标。在示例中,创建了一个子图,绘制了点,并使用transformData转换坐标,然后打印出每个点的像素位置。最后,保存了带有原始DPI的图像。
摘要由CSDN通过智能技术生成

这样做非常简单,但要了解正在发生的事情,您需要阅读有关matplotlib变换的内容.

transformations tutorial是一个很好的起点.

无论如何,这是一个例子:

import numpy as np

import matplotlib.pyplot as plt

fig, ax = plt.subplots()

points, = ax.plot(range(10), 'ro')

ax.axis([-1, 10, -1, 10])

# Get the x and y data and transform it into pixel coordinates

x, y = points.get_data()

xy_pixels = ax.transData.transform(np.vstack([x,y]).T)

xpix, ypix = xy_pixels.T

# In matplotlib, 0,0 is the lower left corner, whereas it's usually the upper

# right for most image software, so we'll flip the y-coords...

width, height = fig.canvas.get_width_height()

ypix = height - ypix

print 'Coordinates of the points in pixel coordinates...'

for xp, yp in zip(xpix, ypix):

print '{x:0.2f}\t{y:0.2f}'.format(x=xp,

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值