|
| 1 | +#Author: Listen |
| 2 | +#!/usr/bin/env python3 |
| 3 | +#-*- coding:utf-8 -* |
| 4 | + |
| 5 | +import matplotlib.pyplot as plt |
| 6 | +import numpy as np |
| 7 | +from mpl_toolkits.mplot3d import Axes3D |
| 8 | +from matplotlib import cm |
| 9 | + |
| 10 | +X = np.arange(-5, 5, 0.25) |
| 11 | +Y = np.arange(-5, 5, 0.25) |
| 12 | +X, Y = np.meshgrid(X, Y) |
| 13 | +R = np.sqrt(X**2 + Y**2) |
| 14 | +Z = np.sin(R) |
| 15 | + |
| 16 | +fig = plt.figure(1,figsize=(14,6)) |
| 17 | +ax1 = fig.add_subplot(1,2,1,projection='3d') |
| 18 | +p1 = ax1.plot_surface(X,Y,Z, rstride=2,cstride=1,linewidth=0, |
| 19 | + antialiased=False) |
| 20 | + |
| 21 | +ax2 = fig.add_subplot(1,2,2,projection='3d') |
| 22 | +p2 = ax2.plot_surface(X,Y,Z, rstride=1,cstride=1,linewidth=0, |
| 23 | + cmap=cm.coolwarm,antialiased=False) |
| 24 | +cb = fig.colorbar(p2,shrink=0.5) |
| 25 | +fig.savefig('../savefig/plot_surface.png') |
| 26 | + |
| 27 | + |
| 28 | +fig2 = plt.figure(2,figsize=(8,6)) |
| 29 | +ax3 = fig2.add_subplot(1,1,1,projection='3d') |
| 30 | +p3 = ax3.plot_wireframe(X,Y,Z,rstride=2,cstride=1) |
| 31 | +fig2.savefig('../savefig/plot_wireframe.png') |
| 32 | + |
| 33 | + |
| 34 | +fig3 = plt.figure(3,figsize=(8,6)) |
| 35 | +ax4 = fig3.add_subplot(1,1,1,projection='3d') |
| 36 | +ax4.plot_surface(X,Y,Z,cstride=1,rstride=1,alpha=0.25) |
| 37 | +cset_z = ax4.contour(X,Y,Z,zdir='z',offset=-0.9, cmap=cm.coolwarm) |
| 38 | +cset_x = ax4.contour(X,Y,Z,zdir='x',offset=-6.0, cmap=cm.coolwarm) |
| 39 | +cset_y = ax4.contour(X,Y,Z,zdir='y',offset= 6.0, cmap=cm.coolwarm) |
| 40 | + |
| 41 | +ax4.set_xlim3d(-2*np.pi,2*np.pi) |
| 42 | +ax4.set_ylim3d(-2*np.pi,2*np.pi) |
| 43 | +ax4.set_zlim3d(-2*np.pi,2*np.pi) |
| 44 | +fig3.savefig('../savefig/plot_surface2.png') |
| 45 | + |
| 46 | +fig4 = plt.figure(figsize=(12,6)) |
| 47 | +ax5 = fig4.add_subplot(1,2,1,projection='3d') |
| 48 | +ax5.plot_surface(X,Y,Z,cstride=1,rstride=1,alpha=0.25) |
| 49 | +ax5.view_init(30,45) |
| 50 | +ax6 =fig4.add_subplot(1,2,2,projection='3d') |
| 51 | +ax6.plot_wireframe(X,Y,Z,rstride=2,cstride=1) |
| 52 | +ax6.view_init(70,30) |
| 53 | +fig4.tight_layout() |
| 54 | +fig4.savefig('../savefig/plot_wireframe2.png') |
| 55 | +plt.show() |
| 56 | + |
| 57 | + |
| 58 | + |
| 59 | + |
0 commit comments