Plot
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import matplotlib.pyplot as plt | |
x = np.linspace(-5, 5, 200) # x data, shape=(100, 1) | |
y1 = 2 * x #... | |
y2 = x ** 2 + 2 | |
y3 = sin(x) | |
plt.figure(1, figsize=(8, 6)) | |
plt.subplot(221) | |
plt.plot(x, y1, c='red', label='y1') | |
plt.ylim(-1, 5) | |
plt.legend(loc='best') | |
plt.subplot(222) | |
plt.plot(x, y2, c='red', label='y2') | |
plt.ylim((-0.2, 1.2)) | |
plt.legend(loc='best') | |
plt.subplot(223) | |
plt.plot(x, y3, c='red', label='y3') | |
plt.ylim((-1.2, 1.2)) | |
plt.legend(loc='best') | |
plt.subplot(224) | |
plt.plot(x, y4, c='red', label='y4') | |
plt.ylim((-0.2, 6)) | |
plt.legend(loc='best') | |
plt.show() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import matplotlib.pyplot as plt | |
# tensorflow | |
# 这种方式可以动态的画图,我们可以动态的看到gd的优化过程 | |
plt.ion() # something about plotting | |
for step in range(100): | |
# train and net output | |
_, acc, pred = sess.run([train_op, accuracy, output], {tf_x: x, tf_y: y}) | |
if step % 2 == 0: | |
# plot and show learning process | |
plt.cla() | |
plt.scatter(x[:, 0], x[:, 1], c=pred.argmax(1), | |
s=100, lw=0, cmap='RdYlGn') | |
plt.text(1.5, -4, 'Accuracy=%.2f' % | |
acc, fontdict={'size': 20, 'color': 'red'}) | |
plt.pause(0.1) | |
plt.ioff() | |
plt.show() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment