Displaying Data in a Scatterplot Can Help Us See the Extent to Which Two Variables Are
In that location are 2 ways to create a scatterplot using data from a pandas DataFrame:
ane. Use pandas.DataFrame.plot.besprinkle
One way to create a scatterplot is to use the built-in pandas plot.scatter() function:
import pandas equally pd df.plot.scatter(10 = 'x_column_name', y = 'y_columnn_name')
2. Utilize matplotlib.pyplot.scatter
Another way to create a scatterplot is to employ the Matplotlib pyplot.scatter() function:
import matplotlib.pyplot as plt plt.scatter(df.ten, df.y)
This tutorial provides an instance of how to utilise each of these methods.
Example 1: Apply Pandas
The post-obit code shows how to use the plot.scatter() function to create a simple scatterplot:
import pandas as pd #create DataFrame df = pd.DataFrame({'x': [i, 3, 3, 4, five, 7, 9, 12, xiii, 15], 'y': [5, 7, 9, seven, 6, 12, 14, 18, 15, 22]}) #create scatterplot df.plot.scatter(x='x', y='y')
Annotation that you tin apply thedue south andc arguments to modify the size and color of the points, respectively:
df.plot.besprinkle(ten='x', y='y', s=threescore, c='green')
Example two: Use Matplotlib
The following code shows how to use the pyplot.scatter() function to create a scatterplot:
import pandas as pd import matplotlib.pyplot as plt #create DataFrame df = pd.DataFrame({'x': [1, 3, 3, 4, v, 7, ix, 12, 13, 15], 'y': [five, 7, nine, 7, six, 12, fourteen, 18, fifteen, 22]}) #create scatterplot plt.scatter(df.ten, df.y)
Annotation that yous can use thes andc arguments to change the size and colour of the points, respectively:
plt.scatter(df.ten, df.y, s=60, c='purple')
You tin can find more Python tutorials here.
Source: https://www.statology.org/pandas-scatter-plot/
0 Response to "Displaying Data in a Scatterplot Can Help Us See the Extent to Which Two Variables Are"
Post a Comment