- 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=1739366892-mskhuuyjmfJk7sTHFRulAbi3QoyguNZW-0-9bc198819da76232a8b4e60b18772d61)
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=1739366892-wILyMRs04Grv8eei4f6bAoMbi2g6E18K-0-0eaba8b2d9ad8e975701502435ab4514)
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=1739366892-PrNjxysYMXHCP1BcRlHyojzUaqWhFySl-0-6de7be2c7fa59822a8657914248708c0)