Consider the following code running in iPython/Jupyter Notebook:
from pandas import * %matplotlib inline ys = [[0,1,2,3,4],[4,3,2,1,0]] x_ax = [0,1,2,3,4] for y_ax in ys: ts = Series(y_ax,index=x_ax) ts.plot(kind='bar', figsize=(15,5))
I would expect to have 2 separate plots as output, instead, I get the two series merged in one single plot. Why is that? How can I get two separate plots keeping the for
loop?
Capturing Output With %%capture IPython has a cell magic, %%capture , which captures the stdout/stderr of a cell. With this magic you can discard these streams or store them in a variable. By default, %%capture discards these streams. This is a simple way to suppress unwanted output.
%%writefile lets you output code developed in a Notebook to a Python module. The sys library connects a Python program to the system it is running on.
Just add the call to plt.show()
after you plot the graph (you might want to import matplotlib.pyplot
to do that), like this:
from pandas import Series import matplotlib.pyplot as plt %matplotlib inline ys = [[0,1,2,3,4],[4,3,2,1,0]] x_ax = [0,1,2,3,4] for y_ax in ys: ts = Series(y_ax,index=x_ax) ts.plot(kind='bar', figsize=(15,5)) plt.show()
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With