- Mastering Machine Learning for Penetration Testing
- Chiheb Chebbi
- 117字
- 2021-06-25 21:03:06
Matplotlib
As you know, visualization plays a huge role in gaining insights from data, and is also very important in machine learning. Matplotlib is a visualization library used for plotting by data scientists. You can get a clearer understanding by visiting its official website at https://matplotlib.org:
![](https://epubservercos.yuewen.com/EA05D4/19470392208878206/epubprivate/OEBPS/Images/Chapter_194.jpg?sign=1734393840-SZgKMqY8j9MQIr3vek4FrTaIM5CpcuiK-0-8f7d52da7ac3ca9e5cec361a8b7bb66f)
To install it on an Ubuntu machine, use the following command:
sudo apt-get install python3-matplotlib
![](https://epubservercos.yuewen.com/EA05D4/19470392208878206/epubprivate/OEBPS/Images/Chapter_185.jpg?sign=1734393840-kcH65gapJrrnYqwMovpURRhXXn8ylZcz-0-0d16e10c40b1aeefd0602096985444f1)
To import the required packages, use import:
import matplotlib.pyplot as plt
import numpy as np
Use this example to prepare the data:
x = np.linspace(0, 20, 50)
To plot it, add this line:
plt.plot(x, x, label='linear')
To add a legend, use the following:
plt.legend()
Now, let's show the plot:
plt.show()
Voila! This is our plot:
![](https://epubservercos.yuewen.com/EA05D4/19470392208878206/epubprivate/OEBPS/Images/Chapter_13.jpg?sign=1734393840-vIWQktnXuJUoG0wF2pvCMjRQQUnZ5P1w-0-3b4ca839abd5486c0c25745285ebe279)