![Python Data Analysis(Second Edition)](https://wfqqreader-1252317822.image.myqcloud.com/cover/371/36701371/b_36701371.jpg)
Visualizing data using Matplotlib
We shall learn about visualizing the data in a later chapter. For now, let's try loading two sample datasets and building a basic plot. First, install the sklearn library from which we shall load the data using the following command:
$ pip3 install scikit-learn
Import the datasets using the following command:
from sklearn.datasets import load_iris from sklearn.datasets import load_boston
Import the Matplotlib plotting module:
from matplotlib import pyplot as plt %matplotlib inline
Load the iris
dataset, print the description of the dataset, and plot column 1 (sepal length) as x
and column 2 (sepal width) as y
:
iris = load_iris() print(iris.DESCR) data=iris.data plt.plot(data[:,0],data[:,1],".")
The resulting plot will look like the following image:
![](https://epubservercos.yuewen.com/A49C99/19470411301656906/epubprivate/OEBPS/Images/image_01_003.jpg?sign=1738890587-Pzj5tPuRJ4e2jDGPSAi7M8jcMPJDPUuY-0-c38a2b774adaf95648c1fc754bb3ca12)
Load the boston dataset, print the description of the dataset and plot column 3 (proportion of non-retail business) as x
and column 5 (nitric oxide concentration) as y
, each point on the plot marked with a + sign:
boston = load_boston() print(boston.DESCR) data=boston.data plt.plot(data[:,2],data[:,4],"+")
The resulting plot will look like the following image:
![](https://epubservercos.yuewen.com/A49C99/19470411301656906/epubprivate/OEBPS/Images/image_01_004.jpg?sign=1738890587-X0dk7krLG6fLZQHE84dFtq4l0d23NBRh-0-cfbe2aa19950fe51af1d0c48d7e08d77)