I would like a piece of code (an analytical model) to produce a series out Jupter outputs so that when the module is run within Jupyter Notebook, it outputs to the notebook a number of tables, HTML outputs and matplotlib charts, in a specific order.
The idea is that the model stores an list of objects, which we can later loop through, displaying each one.
I have managed to make this work with tables and HTML with code like as follows:
from IPython.display import display
from IPython.display import HTML, Image
a = df.head(1)
b = HTML("<p>Hello</p>")
c = df.head(2)
display(a)
display(b)
display(c)
#A more general case would be:
for i in [a,b,c]:
display(i)
However, I am unable to make matplotlib charts (e.g. using df.plot()
) appear in the correct order. Calling plt.show()
enables me to output a single chart in the right order, but doesn't seem to help me if there are multiple charts.
I workaround I've managed to implement is outputting the matplotlib charts to .png and then using Image to display these png images. However, I'd rather avoid having to output loads of .png charts to files if I can help it.
The idea behind all of this is that it allows my analytical model written in Python to output a kind of 'rich' version of logging, where you can 'log' a table or a chart.