-
-
Save Coderx7/cd75644031707ef2625ef4ddd658a7d6 to your computer and use it in GitHub Desktop.
Live plot using %matplotlib notebook in jupyter notebook
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 numpy as np | |
from matplotlib import pyplot as plt | |
class LivePlotNotebook(object): | |
""" | |
Live plot using %matplotlib notebook in jupyter notebook | |
original url : https://gist.github.com/wassname/04e77eb821447705b399e8e7a6d082ce | |
""" | |
def __init__(self, max_iter, test_interval): | |
%matplotlib notebook | |
fig,ax1 = plt.subplots(1,1) | |
ax2 = ax1.twinx() | |
ax1.plot(np.arange(max_iter), train_loss) | |
ax2.plot(test_interval * np.arange(len(test_acc)), test_acc, 'r') | |
ax1.set_xlabel('iteration') | |
ax1.set_ylabel('train loss') | |
ax2.set_ylabel('test accuracy') | |
ax2.set_title('Custom Test Accuracy: {:.2f}'.format(test_acc[-1])) | |
self.ax1 = ax1 | |
self.ax2 = ax2 | |
self.fig = fig | |
self.max_iter = max_iter | |
self.test_interval = test_interval | |
def update(self, train_loss, test_acc): | |
## update action plots | |
self.ax1.clear() | |
self.ax2.clear() | |
self.ax1.plot(np.arange(self.max_iter), train_loss) | |
self.ax2.plot(self.test_interval * np.arange(len(test_acc)), test_acc, 'r') | |
self.ax1.set_xlabel('iteration') | |
self.ax1.set_ylabel('train loss') | |
self.ax2.set_ylabel('test accuracy') | |
self.ax2.set_title('Custom Test Accuracy: {:.2f}'.format(test_acc[-1])) | |
self.fig.canvas.draw() | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment