py3.4
绘制热图:import numpy as npfrom matplotlib import pyplot as pltfrom matplotlib import cm from matplotlib import axesdef draw_heatmap(data,xlabels,ylabels): #cmap = cm.get_cmap('rainbow',1000) cmap=cm.gray figure=plt.figure(facecolor='w') ax=figure.add_subplot(2,1,1,position=[1,1,1,1]) ax.set_yticks(range(len(ylabels))) ax.set_yticklabels(ylabels) ax.set_xticks(range(len(xlabels))) ax.set_xticklabels(xlabels) vmax=data[0][0] vmin=data[0][0] for i in data: for j in i: if j>vmax: vmax=j if j
绘制曲面图from matplotlib import pyplot as pltimport numpy as npfrom mpl_toolkits.mplot3d import Axes3Dfigure = plt.figure()ax = Axes3D(figure)X = np.arange(-10, 10, 0.25)Y = np.arange(-10, 10, 0.25)#网格化数据X, Y = np.meshgrid(X, Y)R = np.sqrt(X**2 + Y**2)Z = np.cos(R)ax.plot_surface(X, Y, Z, rstride=1, cstride=1, cmap='rainbow')plt.show()
绘制曲线图from mpl_toolkits.mplot3d import Axes3Dimport numpy as npimport matplotlib.pyplot as plt#生成画布figure=plt.figure()ax=figure.add_subplot(111,projection='3d')#生成向量z=np.linspace(0,6,1000)r=1x=r*np.sin(np.pi*2*z)y=r*np.cos(np.pi*2*z)ax.plot(x,y,z)plt.show()
使用绘图工具时必须明确已经安装相应的模块