Using Matplotlib in Jupyter Notebook (Anaconda3)

Matplotlib (official website Matplotlib — Visualization with Python  ) is a Python library for creating two-dimensional graphics, which produces publication-quality graphics in various hardcopy formats and cross-platform interactive environments. It is even better to use Jupyter Notebook with Matplotlib.

To use Matplotlib in Anaconda3's Jupyter Notebook, you need to tell Jupyter Notebook to get all the graphics generated by Matplotlib and embed these graphics into the Notebook. The above purpose can be achieved by executing the code "%matplotlib inline": (For how to use Jupyter Notebook in Anaconda3, please refer to https://www.toutiao.com/article/7160267285184119333/?log_from=c3f4e92faed6b_1667215053458  )

The code below, draws the curve y=x^2 (that is, the square of x)

%matplotlib inline
import matplotlib.pyplot as plt
import numpy as np
#x=np.arange(-3, 3, 1)
x=np.linspace(-3, 3, 10,endpoint=True)
print(x)
y=x**2
plt.plot(x,y)

Screenshots of the code and its running results are as follows:

As can be seen from the figure above, the drawn graphics are directly inserted and displayed in the code lines of the Notebook, which is what the code "%matplotlib inline" does (note that python distinguishes between sizes).

When the code needs to be modified and re-executed, the graph will also be dynamically updated.

Related references:

  1. Matplotlib, a 2D plotting library for Python. Matplotlib 
  2. The Application of Python in Machine Learning. Yu Benguo, Sun Yulin. China Water Conservancy and Hydropower Press [Beijing], first edition in June 2019.
  3. A simple example of using Jupyter Notebook in Anaconda3. https://www.toutiao.com/article/7160267285184119333/?log_from=c3f4e92faed6b_1667215053458 
  4. Precautions for using matplotlib drawing in jupyter notebook. Precautions for using matplotlib drawing in jupyter notebook_白马金立侠少年的博客-CSDN Blog_%matplotlib notebook 
  5. Matplotlib API Reference. API Reference — Matplotlib 3.6.0 documentation 
  6. The difference between range, numpy.arange and numpy.linspace of machine learning notes. The difference between range, numpy.arange and numpy.linspace of machine learning notes_51CTO博客_numpy.arange() 
  7. The linspace function in python numpy. The linspace function in python numpy_Dream Painter's Blog-CSDN Blog_linspace 

 

Guess you like

Origin blog.csdn.net/Alexabc3000/article/details/127622425