Scatter Plot Python Matplotlib Example
Create plot fig plt figure ax fig add subplot 1 1 1 axisbg 1 0 for data color group in zip data colors groups.
Scatter plot python matplotlib example. Customizing scatter plot in matplotlib. X y data ax scatter x y alpha 0 8 c color edgecolors none s 30 label group plt title matplot scatter plot plt legend loc 2 plt show. The syntax for scatter method is given below. Rand n 2 0 to 15 point radii plt.
A scatter plot is a diagram where each value in the data set is represented by a dot. Plt scatter x coordinates markers i markers i 1 0 y coordinates markers i markers i 1 1 marker plot markers i len plot markers c colors i len colors label label names i alpha 0 75 plt legend loc upper right fontsize x large plt axis off plt savefig fname plot path format. Import numpy as np import matplotlib pyplot as plt fixing random state for reproducibility np. X axis data an array containing x axis data.
Seed 19680801 n 50 x np. The matplotlib module has a method for drawing scatter plots it needs two arrays of the same length one for the values of the x axis and one for the values of the y axis. First come up with an arbitrary but interesting example. You can change how the plot looks like by supplying the scatter function with additional arguments such as color alpha etc.
Def plot coordinates coordinates plot path markers label names fig num. Suppose the result was announced for a class. Rand n area 30 np. Ax scatter x df gr liv area y df saleprice color blue edgecolors white linewidths 0 1 alpha 0 7 running this code would result in.
X 5 7 8 7 2 17 2 9 4 11 12 9 6 y 99 86 87 88 111 86 103 87 94 78 77 85 86. Data visualization in python scatter plots in matplotlib. Matplotlib pyplot scatter x axis data y axis data s none c none marker none cmap none vmin none vmax none alpha none linewidths none edgecolors none the scatter method takes in the following parameters. Rand n y np.
Matplotlib use svg import matplotlib pyplot as plt plt figure fig num for i in range len markers 1.