Home > Back-end >  How to regrid the grid so that the grid points are spaced at equal distances
How to regrid the grid so that the grid points are spaced at equal distances

Time:12-07

enter image description here

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')

enter image description here 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.

CodePudding user response:

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 (i.e. 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 inch width 16 inch width 8 inch width 4 inch width 2 inch width

  • Related