I'm trying to generate a plot with matplotlib in python using the log values of a data column but I keep running into this error,
Traceback (most recent call last):
File "/home/PycharmProjects/proj1/test.py", line 158, ingraph(file_path)File "/home/PycharmProjects/proj1/test.py", line 90, in graph
y = np.array(np.log2(y1).replace(-np.inf, 0))AttributeError: 'numpy.ndarray' object has no attribute 'replace'
Given below is the code,
def graph(file_path):
dataset1 = pandas.read_csv(file_path)
data1 = dataset1.iloc[:, 5]
x, y1 = get_pdf(data1)
y = np.array(np.log2(y1).replace(-np.inf, 0))
plt.figure()
plt.plot(x, y, color= 'g', label = 'Test')
plt.legend()
output_image = "fig1.png"
plt.savefig(output_image)
plt.close()
plt.figure()
I would really appreciate some help to solve this. Thanks.
pandasSerieshas areplacemethod, but anumpy.ndarraydoes not. Even ify1is a series (I don't knowget_pdf),np.log2()returns an array, not another Series. - hpauljy[y == -np.inf] = 0. The other way would be to replace the -np.inf position before the application of the log (I presume that the np.inf values are where you're doing log2(0)) - Andrew