matplotlib初级用法

import numpy as np
import matplotlib.pyplot as plt
from matplotlib.figure import Figure

x1 = np.linspace(0.0, 5.0)
x2 = np.linspace(0.0, 3.0)

y1 = np.cos(2 * np.pi * x1) * np.exp(-x1)
y2 = np.cos(2 * np.pi * x2)

figure, ax1 = plt.subplots(1,1)
# plt.subplots_adjust(left=0.14, bottom=0.1)
# ax1 = figure.add_axes([0.14, 0.35, 0.77, 0.6 ])
ax1.grid(True)
ax1.plot(x1, y1, 'yo-', label="Test1")
ax1.plot(x2, y2, 'r.-', label='Test2')

plt.legend(bbox_to_anchor=(0., 1.02, 1., .102), loc=3, ncol=2, mode="expand", borderaxespad=0.)

plt.show()
print(2)

一下代码只针对 axis=1做修改

import numpy as np
import matplotlib.pyplot as plt
from matplotlib.figure import Figure

x1 = np.linspace(0.0, 5.0)
x2 = np.linspace(0.0, 3.0)

y1 = np.cos(2 * np.pi * x1) * np.exp(-x1)
y2 = np.cos(2 * np.pi * x2)

figure, ax1 = plt.subplots(1,2)
# plt.subplots_adjust(left=0.14, bottom=0.1)
# ax1 = figure.add_axes([0.14, 0.35, 0.77, 0.6 ])
ax1=ax1[0]
ax1.grid(True)
ax1.plot(x1, y1, 'yo-', label="Test1")
ax1.plot(x2, y2, 'r.-', label='Test2')

plt.legend(bbox_to_anchor=(0., 1.02, 1., .102), loc=3, ncol=2, mode="expand", borderaxespad=0.)

plt.show()
print(2)

import numpy as np
import matplotlib.pyplot as plt
fig = plt.figure()  # an empty figure with no axes

fig, ax1 = plt.subplots(2, 2) 

x1 = np.linspace(0.0, 5.0)
x2 = np.linspace(0.0, 3.0)
 
y1 = np.cos(2 * np.pi * x1) * np.exp(-x1)
y2 = np.cos(2 * np.pi * x2)


ax1[0,0].plot(x1, y1, 'yo-', label="Test1")
ax1[1,1].plot(x2, y2, 'r.-', label='Test2')
ax1[0,0].show()
print (233)

 

猜你喜欢

转载自blog.csdn.net/Gussss/article/details/90019700