【问题标题】:Crop plot 1 according to the shape of plot 2根据地块 2 的形状裁剪地块 1
【发布时间】:2016-10-24 15:28:33
【问题描述】:

我正在尝试使用 plt.pcolormesh 绘制热图,然后使用 plt.scatter 绘制我的图形的轮廓,我想根据最后一个图的形状裁剪结果,即轮廓.

这似乎并不难做到,但我仍然没有设法做到或找到任何东西。这是我的代码和图片来说明,谢谢您的帮助!

plt.rcParams["figure.figsize"] = (10.0, 10.0) 
plt.axis("off")
plt.pcolormesh(x, y, intens)
plt.colorbar()
coord = np.genfromtxt("myfile.csv", delimiter = ' ')
x = [coord[i][0] for i in range(0, len(coord))]
y = [coord[i][1] for i in range(0, len(coord))]
plt.scatter(x, y, c = 'k', s = 1.)

Image here

【问题讨论】:

    标签: python matplotlib plot crop


    【解决方案1】:

    您可以只使用 plt.xlim() 和 plt.ylim() 并为它们提供新图形的坐标。这是代码的修改版本:

    plt.rcParams['figure.figsize'] = (10.0, 10.0)
    plt.axis('off')
    plt.pcolormesh(x, y, intens)
    plt.colorbar()
    coord = np.genfromtxt('myfile.csv', delimiter=' ')
    x = coord[:, 0]
    y = coord[:, 1]
    
    plt.scatter(x, y, c='k', s=1.)
    
    plt.xlim([np.min(x), np.max(x)])
    plt.ylim([np.min(y), np.max(y)])
    

    【讨论】:

    • 感谢您的帮助,特别是对于采用 x 和 y 坐标的较短版本,如您所见,我是 python 的初学者:p 我实际上得到了相同的结果,它是缩放到第二个图形的大小,但我想对其进行裁剪,使其仅跟随轮廓。所以在这里我想删除白色图形之外的所有内容:Here is the example
    猜你喜欢
    • 1970-01-01
    • 2019-05-20
    • 1970-01-01
    • 2012-01-31
    • 1970-01-01
    • 1970-01-01
    • 2012-07-12
    • 2021-10-18
    • 1970-01-01
    相关资源
    最近更新 更多