In [1]:
import sys
print(sys.version)
At this point anything above python 3.5 should be ok.
In [2]:
import numpy as np
np.__version__
Out[2]:
In [3]:
import matplotlib as mpl
from matplotlib import pyplot as plt
mpl.__version__
Out[3]:
In [4]:
x = np.linspace(-3.14, 3.14, num=100)
y = np.sin(x)
plt.plot(x, y)
plt.xlabel('x values')
plt.ylabel('y')
plt.title('y=sin(x)')
plt.show()
In [5]:
x = np.linspace (-1, 1, num =100)
y = np.linspace (-1, 1, num =100)
xx, yy = np.meshgrid (x, y)
z = np.sin(xx**2 + yy**2 + yy)
plt.pcolormesh(x, y, z, shading = 'gouraud')
plt.show()
In [6]:
#change the colormaps
#mpl.rcParams['image.cmap'] = 'viridis'
mpl.rcParams['image.cmap'] = 'jet'
#mpl.rc('image', cmap='jet')
#mpl.rc('image', cmap='hsv')
plt.pcolormesh(x, y, z, shading = 'gouraud')
plt.show()
In [7]:
#use imshow
plt.imshow(z, aspect='auto')
plt.show()
In [8]:
from mpl_toolkits.mplot3d import Axes3D
from matplotlib import cm
fig = plt.figure(figsize=(12,8))
ax = fig.gca(projection='3d')
ax.plot_surface(xx, yy, z, rstride=5, cstride=5, cmap=cm.coolwarm, linewidth=1, antialiased=True)
plt.show()
In [9]:
fig = plt.figure(figsize=(12,8))
ax = fig.gca(projection='3d')
ax.plot_wireframe(xx, yy, z, rstride=5, cstride=5, antialiased=True)
plt.show()
In [11]:
fig = plt.figure(figsize=(20,15))
#create the subplots
ax = fig.add_subplot(2,2,1)
bx = fig.add_subplot(2,2,2)
cx = fig.add_subplot(2,2,3, projection='3d')
dx = fig.add_subplot(2,2,4, projection='3d')
#the sin
ax.plot(np.linspace(-np.pi,np.pi,100), np.sin(np.linspace(-np.pi,np.pi,100)))
ax.scatter(np.linspace(-np.pi,np.pi,100), np.cos(np.linspace(-np.pi,np.pi,100)))
ax.set_xlabel('x values')
ax.set_ylabel('y')
ax.set_title('y=sin(x)')
#the image
bx.imshow(z, aspect='auto')
bx.set_xlabel('x')
bx.set_ylabel('y')
bx.set_title('Some image')
#the surface
cx.set_xlabel('some x')
cx.set_ylabel('some y')
cx.set_zlabel('some z')
cx.set_title('The surface')
cx.plot_surface(xx, yy, z, rstride=5, cstride=5, cmap=cm.coolwarm, linewidth=1, antialiased=True)
#the wireframe
dx.set_xlabel('some x')
dx.set_ylabel('some y')
dx.set_zlabel('some z')
dx.set_title('The wireframe')
dx.plot_wireframe(xx, yy, z, rstride=4, cstride=4, antialiased=True)
plt.show()
In [ ]: