一、 matplotlib and seaborn
1. 中文设置
import matplotlib.pyplot as plt plt.rcParams['font.sans-serif']=['SimHei'] plt.rcParams['axes.unicode_minus']=False
2. 带标签散点图
import matplotlib.pyplot as plt def scatter_with_label(x,y,labl): plt.scatter(x,y) for x_,y_,label_ in zip(x,y,label): plt.text(x_, y_, label_) scatter_with_label(x,y,label) plt.show()
3. matplotlib 在 jupyter 中展示
使用%maytplotlib notebook
还是 %matplotlib widget
均可以进入交互式绘图模式。
出现Javascript Error: IPython is not defined
结果:
Javascript Error: IPython is not defined in JupyterLab - Stack Overflow
conda
conda install -c conda-forge ipympl # If using JupyterLab 2 conda install nodejs jupyter labextension install @jupyter-widgets/jupyterlab-manager jupyter lab build # Later, if updating a previous Lab install: conda install ipympl jupyter lab build
pip
pip install ipympl # If using JupyterLab 2 pip install nodejs-bin jupyter labextension install @jupyter-widgets/jupyterlab-manager jupyter labextension install jupyter-matplotlib