在轮廓上绘制点-Matplotlib / Python

pceccon

我正在尝试使用Matplotlib在轮廓上绘制一些点。

我有要从中绘制轮廓的标量场。但是,我的ndarray的尺寸为0 x 20,但是我的实际空间从-4到4不等。

我可以使用以下代码绘制此轮廓:

x, y = numpy.mgrid[-4:4:20*1j, -4:4:20*1j]

# Draw the scalar field level curves
cs = plt.contour(scalar_field, extent=[-4, 4, -4, 4])
plt.clabel(cs, inline=1, fontsize=10)

问题在于,因为我必须在该图上绘制一些点,并且这些点是使用ndarray获得的,即,我得到的点随此数组维数而变化。

我试图使用以下代码绘制这些点:

def plot_singularities(x_dim, y_dim, steps, scalar_field, min_points, max_points, file_path):
    """
    :param x_dim : the x dimension of the scalar field
    :param y_dim : the y dimension of the scalar field
    :param steps : the discretization of the scalar field
    :param file_path : the path to save the data
    :param scalar_field : the scalar_field to be plot
    :param min_points : a set (x, y) of min points of the scalar field
    :param max_points : a set (x, y) of max points of the scalar field
    """
    min_points_x = min_points[0]
    min_points_y = min_points[1]
    max_points_x = max_points[0]
    max_points_y = max_points[1]

    plt.figure()

    x, y = numpy.mgrid[-x_dim:x_dim:steps*1j, -y_dim:y_dim:steps*1j]

    # Draw the scalar field level curves
    cs = plt.contour(scalar_field, extent=[-x_dim, x_dim, -y_dim, y_dim])
    plt.clabel(cs, inline=1, fontsize=10)

    # Draw the min points
    plt.plot(min_points_x, min_points_y, 'ro')

    # Draw the max points
    plt.plot(max_points_x, max_points_y, 'bo')

    plt.savefig(file_path + '.png', dpi=100)
    plt.close()

但是我得到了这张图片:

在此处输入图片说明

这是不正确的。

如果我更改此行:

cs = plt.contour(scalar_field, extent=[-x_dim, x_dim, -y_dim, y_dim])

对于那个:

cs = plt.contour(scalar_field)

在此处输入图片说明

I get the desired behavior, but the extents doesn't show my real data space, but the ndarray dimension.

At last, if I don't plot these points (comment the plot() lines), I can the extents that I want:

在此处输入图片说明

But I have to plot the points. Both data are in the same space. But the contour() function allows me to specify the grid. I could found a manner to do this when plotting the points.

How can I properly set the extents?

amd

If you don't provide x and y data corresponding to the scalar field, contour uses integer values up to the size of the array. That is why the axes are displaying the dimension of the array. The parameters extent should give the minimum and maximum x and y values; I assume this is what you mean by "data space." So the call to contour would be:

contour(scalar_field,extent=[-4,4,-4,4])

This can be reproduced by specifying x and y data:

contour(numpy.linspace(-4,4,20),numpy.linspace(-4,4,20),scalar_field)

然后,轮廓看起来与第一个绘图完全相同。我认为这是不正确的原因,因为最小和最大点不在正确的位置。根据您所提供的信息,这是因为min_pointsmax_points你传递给你的函数是指数的阵列scalar_field,所以它们对应于整数,而不是实际的xy值。通过定义以下内容,尝试使用这些索引来访问xy点:

x=numpy.linspace(-4,4,20)
y=numpy.linspace(-4,4,20)

例如,如果最小点为(0,1),则对应于(x[0], y[1])我认为使用可以完成类似的操作mgrid,但我自己从未使用过。

本文收集自互联网,转载请注明来源。

如有侵权,请联系[email protected] 删除。

编辑于
0

我来说两句

0条评论
登录后参与评论

相关文章

来自分类Dev

matplotlib绘制椭圆轮廓

来自分类Dev

Python / Matplotlib /绘制函数

来自分类Dev

Python matplotlib 轮廓图

来自分类Dev

图像中的角点以在 Matlab 或 Python 中重新绘制轮廓

来自分类Dev

Python matplotlib无法在椭圆曲线y ^ 2 + x ^ 3 + x ^ 2 = 0上绘制Acnode(孤立点)

来自分类Dev

在Python / matplotlib中用足够的刻度线绘制点图?

来自分类Dev

如何在Python-Matplotlib-Basemap中绘制特定形状的轮廓图

来自分类Dev

在Python中,Matplotlib的Contour函数可以返回特定轮廓线的点吗?

来自分类Dev

matplotlib绘制点很慢

来自分类Dev

Python:Matplotlib避免绘制间隙

来自分类Dev

Python并绘制直方图(使用matplotlib)

来自分类Dev

Matplotlib:如何在图形上绘制点而不是在按钮上绘制点?

来自分类Dev

python在matplotlib.image.AxesImage对象上绘制峰

来自分类Dev

在 tkinter Python 上使用 matplotlib 绘制线条时出错

来自分类Dev

Python Matplotlib图像+点图

来自分类Dev

Matplotlib / python可点击的点

来自分类Dev

Python Matplotlib线图与轮廓/ imshow对齐

来自分类Dev

在matplotlib python中删除散点图的轮廓颜色

来自分类Dev

如何比较两个轮廓路径在视觉上是否相似-Python / Matplotlib

来自分类Dev

在matplotlib中绘制圆形轮廓线

来自分类Dev

使用Matplotlib绘制轮廓和线框图

来自分类Dev

Matplotlib:如何绘制轮廓图?

来自分类Dev

使用forio轮廓在球体上绘制点

来自分类Dev

matplotlib 中的轮廓未绘制指定数量的轮廓

来自分类Dev

Matplotlib 底图:删除绘制点

来自分类Dev

在Python中使用matplotlib和带有numpy的数组绘制3D点

来自分类Dev

Matplotlib轮廓

来自分类Dev

Python-Matplotlib,绘制常量字段

来自分类Dev

使用matplotlib在python中绘制堆叠的直方图

Related 相关文章

  1. 1

    matplotlib绘制椭圆轮廓

  2. 2

    Python / Matplotlib /绘制函数

  3. 3

    Python matplotlib 轮廓图

  4. 4

    图像中的角点以在 Matlab 或 Python 中重新绘制轮廓

  5. 5

    Python matplotlib无法在椭圆曲线y ^ 2 + x ^ 3 + x ^ 2 = 0上绘制Acnode(孤立点)

  6. 6

    在Python / matplotlib中用足够的刻度线绘制点图?

  7. 7

    如何在Python-Matplotlib-Basemap中绘制特定形状的轮廓图

  8. 8

    在Python中,Matplotlib的Contour函数可以返回特定轮廓线的点吗?

  9. 9

    matplotlib绘制点很慢

  10. 10

    Python:Matplotlib避免绘制间隙

  11. 11

    Python并绘制直方图(使用matplotlib)

  12. 12

    Matplotlib:如何在图形上绘制点而不是在按钮上绘制点?

  13. 13

    python在matplotlib.image.AxesImage对象上绘制峰

  14. 14

    在 tkinter Python 上使用 matplotlib 绘制线条时出错

  15. 15

    Python Matplotlib图像+点图

  16. 16

    Matplotlib / python可点击的点

  17. 17

    Python Matplotlib线图与轮廓/ imshow对齐

  18. 18

    在matplotlib python中删除散点图的轮廓颜色

  19. 19

    如何比较两个轮廓路径在视觉上是否相似-Python / Matplotlib

  20. 20

    在matplotlib中绘制圆形轮廓线

  21. 21

    使用Matplotlib绘制轮廓和线框图

  22. 22

    Matplotlib:如何绘制轮廓图?

  23. 23

    使用forio轮廓在球体上绘制点

  24. 24

    matplotlib 中的轮廓未绘制指定数量的轮廓

  25. 25

    Matplotlib 底图:删除绘制点

  26. 26

    在Python中使用matplotlib和带有numpy的数组绘制3D点

  27. 27

    Matplotlib轮廓

  28. 28

    Python-Matplotlib,绘制常量字段

  29. 29

    使用matplotlib在python中绘制堆叠的直方图

热门标签

归档