Issue
I'm new to matplotlib and I can't set the axis labels for my plot. I also tried plt.xlabel("xlabel") and ax1.set(xlabel="Images") but both have failed. Any ideas?
import matplotlib.pyplot as plt
import matplotlib.animation as animation
fig = plt.figure()
ax1 = fig.add_subplot(1, 1, 1)
fig.suptitle("Cross Entropy Loss", fontsize=20)
ax1.set_xlabel('xlabel')
ax1.set_ylabel('ylabel')
def animate(i):
pullData = open("loss1.txt", "r").read()
dataArray = pullData.split('\n')
xar = []
yar = []
for eachLine in dataArray:
if len(eachLine) > 1:
x, y = eachLine.split(',')
xar.append(int(x))
yar.append(int(y))
ax1.clear()
ax1.plot(xar, yar)
ani = animation.FuncAnimation(fig, animate, interval=1000)
plt.title("Cross Entropy Loss")
plt.show()
Solution
You're clearing your axes when doing "ax1.clear()", for that reason "ax1.set_xlabel('xlabel')" and "ax1.set_ylabel('ylabel')" are not showing what you want.
To solve this simply put both "set_x_label" and "set_y_label" after clearing ax1. The code should resemble the following:
...
for eachLine in dataArray:
if len(eachLine) > 1:
x, y = eachLine.split(',')
xar.append(int(x))
yar.append(int(y))
ax1.clear()
ax1.set_xlabel('xlabel')
ax1.set_ylabel('ylabel')
ax1.plot(xar, yar)
...
Answered By - AarónRF
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.