
%matplotlib inline
import matplotlib.pyplot as plt
from matplotlib.font_manager import FontProperties
font = FontProperties(fname=r"c:\windows\fonts\msyh.ttc", size=10)
def runplt():
? ? plt.figure()
? ? plt.title('披薩價(jià)格與直徑數(shù)據(jù)', fontproperties=font)
? ? plt.xlabel('直徑(英寸)',fontproperties=font)
? ? plt.ylabel('價(jià)格(美元)', fontproperties=font)
? ? plt.axis([0, 25, 0, 25])
? ? plt.grid(True)
? ? return plt
plt = runplt()
x = [[6], [8], [10], [14], [18]]
y = [[7], [9], [13], [17.5], [18]]
plt.plot(x, y, 'k.')
plt.show()

上圖中,'x'軸表示披薩直徑,'y'軸表示披薩價(jià)格。能夠看出,披薩價(jià)格與其直徑正相關(guān),這與我們的日常經(jīng)驗(yàn)也比較吻合