Skip to content

Instantly share code, notes, and snippets.

@Coderx7
Forked from wassname/live_plot_notebook.py
Last active March 28, 2018 19:07
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Coderx7/cd75644031707ef2625ef4ddd658a7d6 to your computer and use it in GitHub Desktop.
Save Coderx7/cd75644031707ef2625ef4ddd658a7d6 to your computer and use it in GitHub Desktop.
Live plot using %matplotlib notebook in jupyter notebook
#برای نمایش بلادرنگ نمودار ترینینگ و تست ما
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