Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/294.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_Matplotlib_Pixel_Contour - Fatal编程技术网

Python 获取matplotlib等高线图的像素位置

Python 获取matplotlib等高线图的像素位置,python,matplotlib,pixel,contour,Python,Matplotlib,Pixel,Contour,我有一个等高线图应用程序,我想知道轴原点的像素位置。我已经通读了这本书,但它似乎工作不正常 以下是根据程序改编的代码: 输出为: 来源:[80.48.] 如下图所示: 然而,当我用一个以像素为单位显示光标位置的编辑器(GIMP)来查看这一点时,它将原点位置显示为(100540)。我知道Matplotlib的原点在左下角,GIMP从左上角开始计数,因此调整图像大小(800600)可以得到(100,60)的转换位置 有什么想法吗?这张图的左下角用红色标出了(80,48)的大致位置。 使用matp

我有一个等高线图应用程序,我想知道轴原点的像素位置。我已经通读了这本书,但它似乎工作不正常

以下是根据程序改编的代码:

输出为: 来源:[80.48.]

如下图所示:

然而,当我用一个以像素为单位显示光标位置的编辑器(GIMP)来查看这一点时,它将原点位置显示为(100540)。我知道Matplotlib的原点在左下角,GIMP从左上角开始计数,因此调整图像大小(800600)可以得到(100,60)的转换位置

有什么想法吗?这张图的左下角用红色标出了(80,48)的大致位置。

使用matplotlib 1.4.3
谢谢

tcaswell解决了这个问题-问题是地物对象和保存的图像文件之间的dpi不匹配。figure()默认为80 dpi,而savefig()默认为100 dpi

所以你可以用两种方法来修复它。。。 更改figure()调用的dpi以匹配savefig()默认值:

或者您可以更改savefig()调用的dpi以匹配figure()默认值:


tcaswell解决了这个问题-问题是地物对象和保存的图像文件之间的dpi不匹配。figure()默认为80 dpi,而savefig()默认为100 dpi

所以你可以用两种方法来修复它。。。 更改figure()调用的dpi以匹配savefig()默认值:

或者您可以更改savefig()调用的dpi以匹配figure()默认值:


确保保存的地物的dpi与地物对象的dpi匹配。默认情况下,它们是80和100,这可能是产生差异的原因。事实就是如此。下面修复了这个问题:plt.figure(dpi=100)你能把它写下来作为你自己问题的答案吗?确保保存的图形的dpi与图形对象的dpi匹配。默认情况下,它们是80和100,这可能是产生差异的原因。事实就是如此。下面解决了这个问题:plt.figure(dpi=100)你能把它写下来作为你自己问题的答案吗?
#!/usr/bin/env python
"""
Illustrate simple contour plotting, contours on an image with
a colorbar for the contours, and labelled contours.

See also contour_image.py.
"""
import matplotlib

matplotlib.use('Agg')

import numpy as np
import matplotlib.cm as cm
import matplotlib.mlab as mlab
import matplotlib.pyplot as plt

matplotlib.rcParams['xtick.direction'] = 'out'
matplotlib.rcParams['ytick.direction'] = 'out'

delta = 0.025
x = np.arange(-3.0, 3.0, delta)
y = np.arange(-2.0, 2.0, delta)
X, Y = np.meshgrid(x, y)
Z1 = mlab.bivariate_normal(X, Y, 1.0, 1.0, 0.0, 0.0)
Z2 = mlab.bivariate_normal(X, Y, 1.5, 0.5, 1, 1)
# difference of Gaussians
Z = 10.0 * (Z2 - Z1)

# Create a simple contour plot with labels using default colors.  The
# inline argument to clabel will control whether the labels are draw
# over the line segments of the contour, removing the lines beneath
# the label
plt.figure()
CS = plt.contour(X, Y, Z)
plt.clabel(CS, inline=1, fontsize=10)
plt.title('Simplest default with labels')

print "Origin:\t", plt.gca().transData.transform((-3.0, -2.0))

plt.savefig("cdemo.png")
plt.figure(dpi=100)
plt.savefig("cdemo.png", dpi=80)