Created
January 15, 2019 14:30
-
-
Save amrakm/be4c89555ef5318aa6827905eb887d3f to your computer and use it in GitHub Desktop.
Dynamically update plots in Jupyter lab
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
# source: https://stackoverflow.com/a/52672859/5554394 | |
from IPython.display import clear_output | |
from matplotlib import pyplot as plt | |
import collections | |
%matplotlib inline | |
def live_plot(data_dict, figsize=(7,5), title=''): | |
clear_output(wait=True) | |
plt.figure(figsize=figsize) | |
for label,data in data_dict.items(): | |
plt.plot(data, label=label) | |
plt.title(title) | |
plt.grid(True) | |
plt.xlabel('epoch') | |
plt.legend(loc='center left') # the plot evolves to the right | |
plt.show(); | |
# Then in a loop you populate a dictionary and you pass it to live_plot(): | |
data = collections.defaultdict(list) | |
for i in range(100): | |
data['foo'].append(np.random.random()) | |
data['bar'].append(np.random.random()) | |
data['baz'].append(np.random.random()) | |
live_plot(data) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment