简体   繁体   中英

How to regrid the grid so that the grid points are spaced at equal distances

在此处输入图像描述

In the picture is shown the grid before. After regriding it with:

x1 = np.linspace(min(x),max(x),len(x)) #where I make the previous x spaced equally with the len(x) = 128
y1 = np.linspace(min(y),max(y),len(y))

XX,YY = np.meshgrid(x1, y1) #MESHING
plt.plot(XX,YY)
plt.title('new grid')

在此处输入图像描述 And I get the new grid. As you can see there is a pattern between colored and a period where the white line appears. How can I change that so the distances between this white lines is consistent after every color line OR to make the white lines disappear? The length of the x should stay the same.

This has more to do with matplotlib than with NumPy or the meshing. How the figure will look like is dependent on its width, the number of (ie 128) lines you draw and the line width.

Here is my code and the results. You can see that for a width of 2 inches there are no white stripes and that not every line is equally thick. For a width of 4 inches there are still occasional white stripes between the colored ones. For a width >= 8 there are white lines, but everything seems to be equally spaced.

import numpy as np
import matplotlib.pyplot as plt

xmin = -4
xmax = 2
ymin = -5
ymax = 5
N = 128

x1 = np.linspace(xmin,xmax,N) 
y1 = np.linspace(ymin, ymax, N)
XX,YY = np.meshgrid(x1, y1) 

for width in [2, 4, 8, 16, 32]:
    plt.figure(figsize=(width,7))
    plt.title(f"Figure width = {width} inches")
    plt.plot(XX,YY)
    plt.savefig(f"so_w{width}.png", bbox_inches='tight',dpi=400)

32英寸宽 16英寸宽 8英寸宽 4英寸宽 2英寸宽

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM