简体   繁体   中英

Python MATPLOT scatter plot

I have the following x and y numpy arrays. I am looking to plot them in a single plot, like dots or points on an XY Grid. In MATLAB I would do hold on, after every plot function call, before it shows me the whole plot.

What would be the alternative of that with PYthon? The following code plots every point, and one has to close the graph, so it can plot the next point on the other graph. However, I am looking to have all the points on the same graph.

Looking for suggestions on how that can be achieved with Python

import numpy as np
import matplotlib.pyplot as plt
a = 12; # Max length of spray wall; a is x direction in FEET
b = 12;  # Max width of spray wall; b is y direction in FEET
w = 1; # Width of spray pattern in INCHES
l = 12 ; # Length of spray pattern in INCHES
l = l/12; # IN FEET

ex = np.linspace(w/2, a - w/2, a*50); # THe resolution here is user preference or the speed
ey = np.linspace (l/2, b - l/2, int(2*b/l) -1); # The resolution here is based on 50 % overlap

for y in ey:
    for x in ex:
        plt.plot(x, y, '*')

        plt.show()

I could not use scatter because ex and ey has to be of same length

Well you can append two lists so that you get (x,y) pairs of the same shape by doing:

point_x =[]
point_y =[]
for y in ey:
    for x in ex:
        point_x.append(x)
        point_y.append(y)

then

plt.scatter (point_x, point_y)

or as importanceofbeingernest said to move plt.show out of the nested loops but plotting takes time

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