matplotlib
清醒思考
有问题可以私信我.
展开
-
legend图例
import matplotlib.pyplot as pltimport numpy as npx = np.linspace(-3, 3, 50)y1 = 2*x+1y2 = x**2plt.figure()plt.xlim((-1, 2))plt.ylim((-2,3))plt.xlabel('I am x')plt.ylabel('I am y')new_ticks = np.l原创 2017-07-17 09:38:06 · 458 阅读 · 0 评论 -
matplotlib 次坐标轴
import matplotlib.pyplot as pltimport numpy as npx = np.arange(0,10,0.1)y1 = 0.05 * x**2y2 = -1*y1fig,ax1 = plt.subplots()ax2 = ax1.twinx()ax1.plot(x,y1,'g-')ax2.plot(x,y2,'b--')ax1.set_xlabel('X原创 2017-07-19 21:25:57 · 486 阅读 · 0 评论 -
matplotlib 图中图显示
简书地址 import matplotlib.pyplot as pltfig = plt.figure()x = [1,2,3,4,5,6,7]y = [1,3,4,2,5,8,6]left,bottom,width,height = 0.1,0.1,0.8,0.8ax1 = fig.add_axes([left,bottom,width,height])ax1.plot(x,y,'r'原创 2017-07-19 09:51:41 · 422 阅读 · 0 评论 -
matploblib 分格显示
简书地址1.方法1 subplot2gridimport matplotlib.pyplot as pltimport matplotlib.gridspec as gridspec# method 1: subplot2gridplt.figure()ax1 = plt.subplot2grid((3,3),(0,0),colspan=3,rowspan=1)ax1.plot([1,2],原创 2017-07-19 09:43:56 · 405 阅读 · 0 评论 -
matplotlib 多合一显示
简书地址 import matplotlib.pyplot as pltplt.figure()plt.subplot(2,1,1)plt.plot([0,1],[0,1])plt.subplot(2,3,4)plt.plot([0,1],[0,2])plt.subplot(2,3,5)plt.plot([0,1],[0,3])plt.subplot(2,3,6)plt.plot([0,1原创 2017-07-19 09:16:38 · 463 阅读 · 0 评论 -
matplotlib 3D 数据
简书地址 import matplotlib.pyplot as pltimport numpy as npfrom mpl_toolkits.mplot3d import Axes3Dfig = plt.figure()ax = Axes3D(fig)# X, Y valueX = np.arange(-4,4,0.25)Y = np.arange(-4,4,0.25)X, Y =原创 2017-07-19 09:10:11 · 396 阅读 · 0 评论 -
matplotlib 图片
简书地址 import matplotlib.pyplot as pltimport numpy as np# image dataa = np.array([0.313660827978, 0.365348418405, 0.423733120134, 0.365348418405, 0.439599930621, 0.525083754405,原创 2017-07-19 09:01:54 · 303 阅读 · 0 评论 -
matplotlib contours 等高线图
简书地址 import matplotlib.pyplot as pltimport numpy as npdef f(x,y): return (1 - x/2 + x**5 + y**3) * np.exp(-x**2 - y**2)n = 256x = np.linspace(-3,3,n)y = np.linspace(-3,3,n)X,Y = np.meshgrid(x,原创 2017-07-19 08:53:54 · 349 阅读 · 0 评论 -
设置坐标轴
import matplotlib.pyplot as pltimport numpy as npx = np.linspace(-3, 3, 50)y1 = 2*x+1y2 = x**2plt.figure()plt.plot(x, y2)plt.plot(x, y1, color='red', linewidth=1,linestyle='--')plt.xlim((-1, 2))p原创 2017-07-17 09:32:24 · 341 阅读 · 0 评论 -
设置坐标轴2
import matplotlib.pyplot as pltimport numpy as npx = np.linspace(-3, 3, 50)y1 = 2*x+1y2 = x**2plt.figure()plt.plot(x, y2)plt.plot(x, y1, color='red', linewidth=1,linestyle='--')plt.xlim((-1, 2))p原创 2017-07-17 09:33:13 · 301 阅读 · 0 评论 -
matplotlib bar 柱状图
简书地址 import matplotlib.pyplot as pltimport numpy as npn = 12X = np.arange(n)Y1 = (1 - X/float(n)) * np.random.uniform(0.5,1.0,n)Y2 = (1 - X/float(n)) * np.random.uniform(0.5,1.0,n)plt.bar(X,+Y1,fa原创 2017-07-19 08:43:54 · 940 阅读 · 0 评论 -
matplotlib scatter 散点图
简书地址 import matplotlib.pyplot as pltimport numpy as npn = 1024X = np.random.normal(0,1,n)Y = np.random.normal(0,1,n)T = np.arctan2(Y,X) # for color value# plt.scatter(X,Y,s=75,c=T,alpha=0.5)plt.s原创 2017-07-19 08:33:49 · 505 阅读 · 0 评论 -
matplotlib Annotation标注
import matplotlib.pyplot as pltimport numpy as npx = np.linspace(-3, 3, 50)y = 2*x + 1plt.figure(num=1, figsize=(8,5),)plt.plot(x, y,)ax = plt.gca()ax.spines['right'].set_color('none')ax.spines['t原创 2017-07-17 10:02:31 · 1408 阅读 · 0 评论 -
matploblib 动画
import numpy as npfrom matplotlib import pyplot as pltfrom matplotlib import animationfig,ax = plt.subplots()x = np.arange(0,2*np.pi,0.01)line, = ax.plot(x,np.sin(x))def animate(i): line.set_yda原创 2017-07-19 21:35:06 · 302 阅读 · 0 评论