Matplotlib Scatter Plot Matrix
Import matplotlib pyplot as plt import pandas as pd from sklearn import datasets matplotlib inline plt style use ggplot in 2.
Matplotlib scatter plot matrix. We start with our imports and tell matplotlib to display visuals inline. Setting this to true will show the grid. Load some data iris datasets load iris iris df pd dataframe iris data columns iris feature names iris df species iris target pd scatter matrix iris df alpha 0 2 figsize 10 10 plt show. Draw a matrix of scatter plots.
Amount of transparency applied. Add a simple legend to a scatter plot. Matplotlib scatterplot matplot has a built in function to create scatterplots called scatter. Import matplotlib pyplot as plt x 1 2 3 4 y 4 1 3 6 plt scatter x y c coral label class 1 x 5 6 7 8 y 1 3 5 2 plt scatter x y c lightblue label class 2 plt legend plt title nuage de points avec matplotlib plt xlabel x plt ylabel y plt savefig scatterplot 09 png plt show.
By the way i prefer the matplotlib solution because i find it a bit more transparent. Parameters frame dataframe alpha float optional. The position of a point depends on its two dimensional value where each value is a position on either the horizontal or vertical dimension. I ll guide you through these 4 steps.
Using the pyplot function legend. A scatter plot is a type of plot that shows the data as a collection of points. X with varying marker size and or color. A matplotlib scatter plot.
The two solutions are fairly similar the whole process is 90 the same the only difference is in the last few lines of code. Pandas uses matplotlib to display scatter matrices. From matplotlib import pyplot from pandas import read csv from pandas tools plotting import scatter matrix path r c pima indians diabetes csv names preg plas pres skin test mass pedi age class data read csv path names names scatter matrix data pyplot show. It can be generated with the help of scatter matrix function on pandas dataframe and plotted with the help of pyplot.
How to add a legend for a scatter plot in matplotlib. Matplotlib pyplot scatter matplotlib pyplot scatter x y s none c none marker none cmap none norm none vmin none vmax none alpha none linewidths none verts none edgecolors none plotnonfinite false data none kwargs source a scatter plot of y vs x with varying marker size and or color.