2

Current, I get 3 separate windows with pyplot... which i don't want... i want to see all of my plots sequentially listed "inline" in a single web browser window similar to jupyter output except with my script running from a windows command line as an ipython script...

# File: plotit.ipy

# toy ipython plotting example
import numpy as np
import matplotlib.pyplot as plt 
%matplotlib

t = np.linspace(0, 10, 100)
y1 = 5*t
y2 = -0.5*t
y3 = 2*t**2

# display as 1st inline graph in "jupyter web browser window"
plt.figure()
plt.plot(t,y1)
plt.show()

# display as 2nd inline graph in "jupyter web browser window"
plt.figure()
plt.plot(t,y2)
plt.show()

# display as 3rd inline graph in "jupyter web browser window"
plt.figure()
plt.plot(t,y3, '.')
plt.show()

This is how I run it from command line using ActiveState Python 3.6:

C:\> ipython 
In [1]: %run testit.ipy
Using matplotlib backend: TkAgg    

Is there's a way to convert a Jupiter document into a ipython script, and run it from the command line as one monolithic script, but still have the matplotlib plots show up "inline" in a jupyter output window sequentially as they are plotted while running the script. Example:

2 Answers 2

2

I don't know if it's possible to emulate a jupyter notebook, without actually running it.

An alternative could be to use the webagg backend. In this case only a single plt.show() call is put at the end to show all three figures on the same page.

import numpy as np
import matplotlib
matplotlib.use("webagg")
import matplotlib.pyplot as plt 


t = np.linspace(0, 10, 100)
y1 = 5*t
y2 = -0.5*t
y3 = 2*t**2

# display as 1st inline graph in "jupyter web browser window"
plt.figure()
plt.plot(t,y1)

# display as 2nd inline graph in "jupyter web browser window"
plt.figure()
plt.plot(t,y2)

# display as 3rd inline graph in "jupyter web browser window"
plt.figure()
plt.plot(t,y3, '.')
plt.show()

When running this a browser window should open, and show the three figures

enter image description here

Sign up to request clarification or add additional context in comments.

Comments

0

Save all plots as image files without displaying them, then write an html file to display all the image files after running python script.

# File: plotit.ipy

# toy ipython plotting example
import numpy as np
import matplotlib.pyplot as plt 

t = np.linspace(0, 10, 100)
y1 = 5*t
y2 = -0.5*t
y3 = 2*t**2

# display as 1st inline graph in jupyter web browser window
fig = plt.figure()
plt.plot(t,y1)
fig.savefig("plot1.png")

# display as 2nd inline graph in jupyter web browser window
fig = plt.figure()
plt.plot(t,y2)
fig.savefig("plot2.png")

# display as 3rd inline graph in jupyter web browser window
fig = plt.figure()
plt.plot(t,y3)
fig.savefig("plot3.png")

html:

<!-- FILE: results.html -->
<html>
<body>
    <img src="plot1.png"/><br>
    <img src="plot2.png"/><br>
    <img src="plot3.png"/><br>
</body>
</html>

Another html results page:

<h1>Results</h1>

<table>

<tr>
<td><img src="plot1.png" style="max-width:100%"/></td>
<td><img src="plot2.png" style="max-width:100%"/></td>
</tr>

<tr>
<td><img src="plot3.png" style="max-width:100%"/></td>
<td><img src="plot1.png" style="max-width:100%"/></td>
</tr>

</table>

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.