TQC+ 網頁資料擷取與分析 Python 3 _ 401 資料:折線圖

說明:
利用程式內提供的數據,依下列要求以matplotlib輸出chart.png圖檔:
  • 設定線條寬度設定為1,線條色彩與樣式各別為藍色虛點線與紅色虛點線
  • 設定軸刻度調整至(0,0)開始至(8,70)
  • 標題設定
    • 圖表標題:Figure 字體大小:24
    • X軸標題:x-Value,字體大小:16
    • Y軸標題:y-Value,字體大小:16
範例輸出:
Alt text

程式碼:
import matplotlib.pyplot as plt

data1 = [1, 4, 9, 16, 25, 36, 49, 64]
data2 = [1, 2, 3, 6, 9, 15, 24, 39]
seq = [1, 2, 3, 4, 5, 6, 7, 8]

plt.plot(seq, data1, "--.b", seq, data2, "--.r")
plt.axis([0,8,0,70])
plt.title("Figure",fontsize = 24)
plt.xlabel("x-Value",fontsize = 16)
plt.ylabel("y-Value",fontsize = 24)

plt.savefig('chart.png')
plt.close()

沒有留言:

張貼留言