1
我想對於繪製多個數據文件創建循環。錯誤在savefig步:ValueError異常:不能轉換浮動NaN的整數
#!/usr/bin/env python
# -*- coding: utf-8 -*-
import pandas as pd
import numpy as np
import matplotlib.pyplot as plt
import glob
import os
pathf1 = r'/home/foo/condt/'
allfiles1 = glob.glob(pathf1 + '/*.csv')
fig1 = plt.figure()
for filee_ in allfiles1:
dfp = pd.read_csv(filee_, sep=',', encoding='utf-8')
ax = plt.subplot(111)
ax.plot(dfp['col3'], dfp['col2'], ls = '-', color='red', marker='x', markersize = 25.0)
ax.errorbar(dfp['col1'], dfp['col2'], yerr=dfp['PN_6_FLUX_ERR'], ls='None', marker = '.')
ax.set_xlim((dfp['col1'].min()-0.1*(dfp['col1'].max()-dfp['col1'].min())), ((dfp['col1'].max()+0.1*(dfp['col1'].max()-dfp['col1'].min()))))
ax.set_ylim((dfp['col2'].min()-dfp['col2'].max()),((dfp['col2'].max()/2.0)+dfp['col2'].max())
ax.grid()
plt.xticks(dfp['col1'])
plt.yticks(dfp['col2'])
plt.xlabel('col1')
plt.ylabel('col2')
plt.title('col1 vs. col2')
filenamee = ''+ str('%02s' %filee_)+'.png'
plt.savefig(filenamee, dpi=600)
plt.clf()
plt.show()
當我跑我得到這個代碼:
plt.savefig(filenamee, dpi=600)
ValueError: cannot convert float NaN to integer
列這樣的文件,
col1 col2 col3
3.39895E-12 52459.7796644
3.62529E-12 52461.7358623
3.67719E-12 52501.6052951
2.26977E-11 56340.081624
3.38851E-11 53574.1580939 53574.1580939
當我刪除代碼一切蜱將是一個正常...但我需要在我的圖表中滴答滴答。我怎麼解決這個問題?
str('%02s'%filee_)的結果是什麼? –
這是給文件的名稱。喜歡這個; /home/foo/filename1.csv ...... /home/foo/filenamen.csv – anniejcannon
你確定嗎? 「/home/foo/%02s.csv」%(filename)的結果是什麼,你打印/這是可能的嗎? –