我試圖從 scv 檔案中讀取資料并繪制它們。讀取程序很容易作業,但通過繪制完全錯過了。我已經用 MATLAB 甚至 Excel 試過了。兩者都繪制正確,但在 python 3 中我有問題。似乎是這樣。 用 python 繪制照片 用 MATLAB 繪制照片
我會很感激你的幫助
filename1=fd.askopenfilename(title='open expander text data to graphic ')
reader=csv.reader(filename1)
xpoints = []
ypoints = []
for line in reader:
xpoints.append(line[0])
ypoints.append(line[1])
xpoints_to_graph=np.array(xpoints[])
ypoints_to_graph=np.array(ypoints[])
plt.plot(xpoints_to_graph,ypoints_to_graph)
uj5u.com熱心網友回復:
每個line都是一個字串元組。因此,xpoints和ypoints是字串串列。Matplotlib 因此會嘗試將所有可能的值作為刻度,這就是繪圖如此混亂的原因。
您應該將 的每個元素line視為一個數字:
xpoints = []
ypoints = []
for line in reader:
xpoints.append(float(line[0]))
ypoints.append(float(line[1]))
或者,使用numpy.loadtxt,它將自動將數字轉換為浮點或整數型別。
轉載請註明出處,本文鏈接:https://www.uj5u.com/houduan/380622.html
標籤:蟒蛇-3.x matplotlib
