准备数据
执行:
import numpy as np
x = np.arange(0,100)
y = x*2
z = x**2
1、导入matplotlib.pyplot 并命名为plt,如何支持Jupyter notebook内部绘图?非Jupyter notebook中如何绘图?
2、创建一个figure对象fig
3、使用add_axes命令在[0,0,1,1]位置创建坐标轴,并命名为ax,设置titles和labels入下图所示:
期望的结果
4、创建一个figure对象,设置两个坐标轴ax1,ax2,位置分别为:[0,0,1,1] 和 [0.2,0.5,.2,.2]
5、调用plot (x,y)绘制图形并显示
6、创建figure对象,在[0,0,1,1]和[0.2,0.5,.4,.4]创建两个坐标轴
7、使用x,y,z数组创建图形如下图所示,注意x,y的定义域
8、使用plt.subplots(nrows=1, ncols=2)创建如下图形
9、使用plot (x,y)和(x,z)并使用linewidth和style
10、重绘以上图形的大小
答案如下
1、导入matplotlib.pyplot 并命名为plt,如何支持Jupyter notebook内部绘图?非Jupyter notebook中如何绘图?
import matplotlib.pyplot as plt
%matplotlib inline
# plt.show() 非notebook绘制
2、创建一个figure对象figfig = plt.figure()
3、使用add_axes命令在[0,0,1,1]位置创建坐标轴,并命名为ax,设置titles和labels入下图所示:
ax = fig.add_axes([0,0,1,1])
ax.plot(x,y)
ax.set_xlabel('x')
ax.set_ylabel('y')
ax.set_title('title')
期望的结果
4、创建一个figure对象,设置两个坐标轴ax1,ax2,位置分别为:[0,0,1,1] 和 [0.2,0.5,.2,.2]
fig = plt.figure()
ax1 = fig.add_axes([0,0,1,1])
ax2 = fig.add_axes([0.2,0.5,.2,.2])
5、调用plot (x,y)绘制图形并显示
ax1.plot(x,y)
ax1.set_xlabel('x')
ax1.set_ylabel('y')
ax2.plot(x,y)
ax2.set_xlabel('x')
ax2.set_ylabel('y')
fig # Show figure object
6、创建figure对象,在[0,0,1,1]和[0.2,0.5,.4,.4]创建两个坐标轴
fig = plt.figure()
ax = fig.add_axes([0,0,1,1])
ax2 = fig.add_axes([0.2,0.5,.4,.4])
7、使用x,y,z数组创建图形如下图所示,注意x,y的定义域
ax.plot(x,z)
ax.set_xlabel('X')
ax.set_ylabel('Z')
ax2.plot(x,y)
ax2.set_xlabel('X')
ax2.set_ylabel('Y')
ax2.set_title('zoom')
ax2.set_xlim(20,22)
ax2.set_ylim(30,50)
fig
8、使用plt.subplots(nrows=1, ncols=2)创建如下图形fig, axes = plt.subplots(nrows=1, ncols=2)
9、使用plot (x,y)和(x,z)并使用linewidth和style
axes[0].plot(x,y,color="blue", lw=3, ls='--')
axes[1].plot(x,z,color="red", lw=3, ls='-')
fig
10、重绘以上图形的大小
fig, axes = plt.subplots(nrows=1, ncols=2,figsize=(12,2))
axes[0].plot(x,y,color="blue", lw=5)
axes[0].set_xlabel('x')
axes[0].set_ylabel('y')
axes[1].plot(x,z,color="red", lw=3, ls='--')
axes[1].set_xlabel('x')
axes[1].set_ylabel('z')
进度介绍
本系列文章共分为26个部分目前已经进行到了第8部分,所有内容计划如下:预热环境搭建Jupyter教程Python速成Python数据分析,NumPy库的使用Python数据分析,Pandas库的使用Python数据分析,Pandas库练习Python数据可视化,MatplotlibPython数据可视化,SeabornPython数据可视化,Pandas内建数据可视化Python数据可视化,Plotly和CufflinksPython数据可视化,Geographical Plotting数据 Capstone 项目机器学习介绍线性回归交叉验证与偏方差逻辑回归算法k-近邻算法决策树与随机森林支持向量机k-means聚类主成分分析推荐系统自然语言处理(NLP)Python大数据与Spark神经网络(NN)与深度学习(DL)
留言与评论(共有 0 条评论) |