1. 程式人生 > >使用matplotlib繪製第一張圖

使用matplotlib繪製第一張圖

如下是博主使用matplotlib學習繪製的一張圖:

import matplotlib.pyplot as plt

x = [1, 2, 3, 4]    # prepare data
y = [10, 20, 25, 30] # prepare data
flg = plt.figure()  # create plot
ax = flg.add_subplot(111)  # plot
ax.plot(x, y, color='lightblue', linewidth=3) # plot and customize plot
ax.scatter([2, 4, 6],[5, 15, 25], color='darkgreen', marker='^')    # plot with scatter
ax.set_xlim(1, 6.5) # limit the x axis
plt.show()  # show plot