1. 程式人生 > 程式設計 >python二維圖製作的例項程式碼

python二維圖製作的例項程式碼

python全程式碼如下

import re
import csv
import matplotlib.pyplot as plt


x=[]
y=[]
m=eval(input())  #輸入折線條數
for i in range(m):
 y.append([])
fo = open("E:\\shu\\2.txt","r",encoding='UTF-8')  
plt.ylim(0,20)      # 設定y軸範圍
for line in fo.readlines(): # 按行輸入
 line=line.split("\n")[0] #分割
 if line !="": 判定是否為空
  don=line.split(" ")
  x.append(don[0])
  for i in range(len(don)-1):  
   y[i].append(eval(don[i+1]))



figsize = 12,8
plt.subplots(figsize=figsize)        # 設定整張圖片大小
plt.grid(True)  # 是否網格化
markes = ['-o','-s','-^','-p','-v','-d','-h','-2','-8','-6']
plt.ylabel('Trade account unit: billion US dollars') #座標命名
plt.xlabel('time') #座標命名
for i in range(m):
 plt.plot(x,y[i],markes[i%12])
plt.legend(['America','china'],loc='upper left')
plt.savefig("Trade account.jpg",dpi=600) #儲存圖片
plt.show()

圖片效果如下

python二維圖製作的例項程式碼

檔案內容如下

2019-10 -47.2 39.65
2019-11 -43.1 38.73
2019-12 -48.9 46.79
2020-01 -45.3 47.29
2020-02 -39.9 19.93
2020-03 -44.4 45.34
2020-04 -49.4 62.93
2020-05 -54.6 46.42
2020-06 -50.7 62.33
2020-07 -63.6 58.93
2020-08 -67.1 37.00
2020-09 -63.9 58.44

總結

到此這篇關於python二維圖製作的文章就介紹到這了,更多相關python二維圖製作內容請搜尋我們以前的文章或繼續瀏覽下面的相關文章希望大家以後多多支援我們!