gpt4 book ai didi

python - savefig 步骤 : ValueError: cannot convert float NaN to integer 出错

转载 作者:太空宇宙 更新时间:2023-11-03 15:52:23 32 4
gpt4 key购买 nike

我正在尝试创建循环来绘制多个数据文件。

#!/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

当我从代码中删除刻度时,一切都会正常......但我的图表中需要刻度。我该如何解决这个问题?

最佳答案

我找到了解决方案。问题根源是 matplotlib 库的版本。我认为这是一种错误。为了解决这个问题,您必须使用下面的终端命令更新 matplotlib_venn 库。

pip install --upgrade matplotlib_venn

关于python - savefig 步骤 : ValueError: cannot convert float NaN to integer 出错,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41164882/

32 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com