You are on page 1of 11

2/27/24, 10:59 AM Data-Visualization-27-02 - Jupyter Notebook

In [2]: import numpy as np


import pandas as pd
import seaborn as sns
import matplotlib.pyplot as plt

In [3]: iris = pd.read_csv('iris.csv')

In [4]: print(iris.head())

sepal_length sepal_width petal_length petal_width species


0 5.1 3.5 1.4 0.2 setosa
1 4.9 3.0 1.4 0.2 setosa
2 4.7 3.2 1.3 0.2 setosa
3 4.6 3.1 1.5 0.2 setosa
4 5.0 3.6 1.4 0.2 setosa

In [5]: print(iris.columns)

Index(['sepal_length', 'sepal_width', 'petal_length', 'petal_width',


'species'],
dtype='object')

In [8]: print(iris.head())

sepal_length sepal_width petal_length petal_width species


0 5.1 3.5 1.4 0.2 setosa
1 4.9 3.0 1.4 0.2 setosa
2 4.7 3.2 1.3 0.2 setosa
3 4.6 3.1 1.5 0.2 setosa
4 5.0 3.6 1.4 0.2 setosa

localhost:8888/notebooks/Data-Visualization-27-02.ipynb# 1/11
2/27/24, 10:59 AM Data-Visualization-27-02 - Jupyter Notebook

In [9]: import pandas as pd


import matplotlib.pyplot as plt
import seaborn as sns


iris = sns.load_dataset('iris')


sns.scatterplot(x='sepal_length', y='sepal_width', data=iris)
plt.title('Scatter plot of Sepal Length vs. Sepal Width')
plt.xlabel('Sepal Length (cm)')
plt.ylabel('Sepal Width (cm)')
plt.show()

localhost:8888/notebooks/Data-Visualization-27-02.ipynb# 2/11
2/27/24, 10:59 AM Data-Visualization-27-02 - Jupyter Notebook

In [12]: ​
iris = sns.load_dataset('iris')


sns.scatterplot(x='sepal_length', y='sepal_width', hue='species', data=iris
plt.title('Scatter plot of Sepal Length vs. Sepal Width')
plt.xlabel('Sepal Length (cm)')
plt.ylabel('Sepal Width (cm)')
plt.show()

localhost:8888/notebooks/Data-Visualization-27-02.ipynb# 3/11
2/27/24, 10:59 AM Data-Visualization-27-02 - Jupyter Notebook

In [15]: import pandas as pd


import matplotlib.pyplot as plt
import seaborn as sns


iris = sns.load_dataset('iris')


sns.lineplot(x=iris.index, y='sepal_length', data=iris, estimator=None)
plt.title('Line Chart of Sepal Length Across Dataset')
plt.xlabel('Sample Index')
plt.ylabel('Sepal Length (cm)')
plt.show()

In [17]: columns = iris.columns.drop(['species'])



x_data = range(0, iris.shape[0])

localhost:8888/notebooks/Data-Visualization-27-02.ipynb# 4/11
2/27/24, 10:59 AM Data-Visualization-27-02 - Jupyter Notebook

In [19]: columns = iris.columns.drop(['species'])



x_data = range(0, iris.shape[0])

fig, ax = plt.subplots()

for column in columns:
ax.plot(x_data, iris[column])

ax.set_title('Iris Dataset')
ax.legend()

No artists with labels found to put in legend. Note that artists whose la
bel start with an underscore are ignored when legend() is called with no a
rgument.

Out[19]: <matplotlib.legend.Legend at 0x1dd2ef4ed90>

In [20]: wine_reviews = pd.read_csv('winemag-data-130k-v2.csv')

localhost:8888/notebooks/Data-Visualization-27-02.ipynb# 5/11
2/27/24, 10:59 AM Data-Visualization-27-02 - Jupyter Notebook

In [21]: ​
fig, ax = plt.subplots()


data = wine_reviews['points'].value_counts()


points = data.index
frequency = data.values


ax.bar(points, frequency)


ax.set_title('Wine Review Scores')
ax.set_xlabel('Points')
ax.set_ylabel('Frequency')

Out[21]: Text(0, 0.5, 'Frequency')

localhost:8888/notebooks/Data-Visualization-27-02.ipynb# 6/11
2/27/24, 10:59 AM Data-Visualization-27-02 - Jupyter Notebook

In [25]: print(iris.columns)
import seaborn as sns
iris = sns.load_dataset('iris')
iris.plot.scatter(x='sepal_length',y='sepal_width',title='Iris Dataset')

Index(['sepal_length', 'sepal_width', 'petal_length', 'petal_width',


'species'],
dtype='object')

Out[25]: <Axes: title={'center': 'Iris Dataset'}, xlabel='sepal_length', ylabel='se


pal_width'>

localhost:8888/notebooks/Data-Visualization-27-02.ipynb# 7/11
2/27/24, 10:59 AM Data-Visualization-27-02 - Jupyter Notebook

In [26]: iris.drop(['sepal_width'], axis=1).plot.line(title='Iris Dataset')


Out[26]: <Axes: title={'center': 'Iris Dataset'}>

In [27]: wine_reviews['points'].plot.hist()

Out[27]: <Axes: ylabel='Frequency'>

localhost:8888/notebooks/Data-Visualization-27-02.ipynb# 8/11
2/27/24, 10:59 AM Data-Visualization-27-02 - Jupyter Notebook

In [28]: iris.plot.hist(subplots=True, layout=(2,2), figsize=(10, 10), bins=20)

Out[28]: array([[<Axes: ylabel='Frequency'>, <Axes: ylabel='Frequency'>],


[<Axes: ylabel='Frequency'>, <Axes: ylabel='Frequency'>]],
dtype=object)

localhost:8888/notebooks/Data-Visualization-27-02.ipynb# 9/11
2/27/24, 10:59 AM Data-Visualization-27-02 - Jupyter Notebook

In [29]: wine_reviews['points'].value_counts().sort_index().plot.bar()

Out[29]: <Axes: xlabel='points'>

In [34]: wine_reviews['points'].value_counts().sort_index().plot.barh()

Out[34]: <Axes: ylabel='points'>

localhost:8888/notebooks/Data-Visualization-27-02.ipynb# 10/11
2/27/24, 10:59 AM Data-Visualization-27-02 - Jupyter Notebook

In [37]: wine_reviews.groupby("country").price.mean().sort_values(ascending=False)[:5

Out[37]: <Axes: xlabel='country'>

localhost:8888/notebooks/Data-Visualization-27-02.ipynb# 11/11

You might also like