5/6/2023 0 Comments Simple scatter plot matplotlibIt can produce scatter plots, 3-D plots, histograms, bar charts, pie charts, and line plots, among other types of Python graphs. The scatter plot shows the relationship between the two variables and how it varies for one variable.Ī comprehensive tool for creating static, animated, and interactive visualisations is offered by the Matplotlib toolbox for Python. To create a scatter plot, we utilise the scatter() function from the matplotlib library. The connections between the dataset are represented by the dots in the graph. In most cases, scatter plots are used to examine the relationship between the variables. Two sets of data are needed to create a scatter plot one set of arrays represents the data on the x-axis, while the second set of arrays represents the data on the y-axis. Using the matplotlib library, we will depict a scatter plot. The data values are represented as dots on the plot. Pl.One kind of graph that has dots plotted in it is called a scatter plot in Python. Pl.scatter(particle_position_nosub, particle_velocity_nosub, color='b', marker='o') Particle_velocity_nosub = np.delete(particle_velocity, v_sub_index) Particle_position_nosub = np.delete(particle_position, v_sub_index) Particle_velocity_sub = np.array(particle_velocity) Particle_position_sub = np.array(particle_position) Particle_position = np.random.rand (N) * xmax V_sub_index = np.random.randint(0, N, N_sub) # 95% of the samples contained within 0, 5 Numpy has great functionality for that without having to use for loops. Please note that you don't have to loop to generate random samples. I have selected a random set v_sub_index of N_sub indices in the correct range ( 0 to N) and draw those (with _sub suffix) from the larger samples particle_position and particle_velocity. It is efficient & leaves the original data intact. Plt.scatter(points_x, points_y, marker="o", color="red")Īs you see, scatter is called once on a subset of the data points (the ones not selected in the sample), and a second time on the sampled subset, and draws each subset with its own marker. Mask = np.array( * sample_size + * (data_size - sample_size)) Here is a way to proceed with masks: import matplotlib.pyplot as plt Maybe a better method is to use a mask? A mask has the advantage of leaving your original data intact and in order. You could also extract the sample points from the data set to prevent marking them twice, but numpy is rather inefficient at deleting or resizing. You will have to decide how you want to select the sample of points - it is isolated in the select_subset function. It uses plt.scatter twice once on the full data set, the other on the sample points. Plt.scatter(select_subset(points_x, SAMPLE_SIZE), Plt.scatter(points_x, points_y, marker=".", color="blue") Points_y = np.random.uniform(-1, 1, size=SIZE) Points_x = np.random.uniform(-1, 1, size=SIZE) Here is a possible solution to have a subset of your points identified with a different marker: import matplotlib.pyplot as plt I had an idea that perhaps I could randomly select a bunch of i values from range(N), and use an ax.scatter() command to plot them on the same axes? The position and velocity change on each iteration of the main loop (there's quite a bit of code), but these are the main initialization and plotting routines. Plt.scatter(particle_position, particle_velocity, s=1, c=norm_xvel, cmap=br_disc, lw=0) Particle_velocity = np.random.normal(0, 5) # Initialize in velocity space Particle_position = np.random.uniform(0, xmax) # Initialize in spatial domain Is there a way to use a different marker for a small subset of the same data?įor reference, the particles are uniformly distributed just using the numpy random sampler, but my code for that is: for i in range(N): # N number of particles This is so I can use them as placeholders to see the motion of individual particles, as well as the bulk material. What I want to be able to do is randomly select a small portion of these particles (say, maybe 100?) and give them a different marker than the rest, even though they're part of the same data set. This command is part of a loop that saves the figure, so I can later animate it. This is being done using matplotlib's plt.scatter. I'm creating a program to plot a large number of points (~10,000, but it will be more later on). Pretty much exactly what the question states, but a little context:
0 Comments
Leave a Reply. |