Bar and Scatter Plots
There are other kinds of graphs pandas allows us to use for visualization. Among them are boxplots, bar plots, scatter plots, etc. To build a respective plot, apply the .plot() method to selected data, and set the kind parameter to plot type you want to build.
Possible values for the kind parameter are the following.
| Value | Kind of plot |
|---|---|
bar or barh | for bar plots |
hist | for histogram |
scatter | for scatter plots |
For instance, to build a scatter plot you also need to set two parameters: x and y. Let's build a scatter plot of total income vs. dwelling price.
12345678# Importing the library import pandas as pd # Reading the file df = pd.read_csv('https://codefinity-content-media.s3.eu-west-1.amazonaws.com/f2947b09-5f0d-4ad9-992f-ec0b87cd4b3f/data4.csv') # Scatter plot total income vs. dwelling price df.plot(kind = 'scatter', x = 'totinch', y = 'valueh')
The same parameters must be set to build a bar plot. For instance, let's build a bar plot with address on the x-axis and total income on the y-axis for the first 20 dwellings.
12345678# Importing the library import pandas as pd # Reading the file df = pd.read_csv('https://codefinity-content-media.s3.eu-west-1.amazonaws.com/f2947b09-5f0d-4ad9-992f-ec0b87cd4b3f/data4.csv') # Scatter plot total income vs. dwelling price df.iloc[:20].plot(kind = 'bar', x = 'address', y = 'totinch')
Obrigado pelo seu feedback!
Pergunte à IA
Pergunte à IA
Pergunte o que quiser ou experimente uma das perguntas sugeridas para iniciar nosso bate-papo
Awesome!
Completion rate improved to 2.56
Bar and Scatter Plots
Deslize para mostrar o menu
There are other kinds of graphs pandas allows us to use for visualization. Among them are boxplots, bar plots, scatter plots, etc. To build a respective plot, apply the .plot() method to selected data, and set the kind parameter to plot type you want to build.
Possible values for the kind parameter are the following.
| Value | Kind of plot |
|---|---|
bar or barh | for bar plots |
hist | for histogram |
scatter | for scatter plots |
For instance, to build a scatter plot you also need to set two parameters: x and y. Let's build a scatter plot of total income vs. dwelling price.
12345678# Importing the library import pandas as pd # Reading the file df = pd.read_csv('https://codefinity-content-media.s3.eu-west-1.amazonaws.com/f2947b09-5f0d-4ad9-992f-ec0b87cd4b3f/data4.csv') # Scatter plot total income vs. dwelling price df.plot(kind = 'scatter', x = 'totinch', y = 'valueh')
The same parameters must be set to build a bar plot. For instance, let's build a bar plot with address on the x-axis and total income on the y-axis for the first 20 dwellings.
12345678# Importing the library import pandas as pd # Reading the file df = pd.read_csv('https://codefinity-content-media.s3.eu-west-1.amazonaws.com/f2947b09-5f0d-4ad9-992f-ec0b87cd4b3f/data4.csv') # Scatter plot total income vs. dwelling price df.iloc[:20].plot(kind = 'bar', x = 'address', y = 'totinch')
Obrigado pelo seu feedback!