2 回答

TA贡献1966条经验 获得超4个赞
我不知道是否可以模拟 jupyter 笔记本,而无需实际运行它。
另一种方法是使用webagg后端。在这种情况下,只plt.show()在末尾放置一个调用以在同一页面上显示所有三个数字。
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()
运行此程序时,应打开一个浏览器窗口,并显示三个数字

TA贡献1831条经验 获得超9个赞
将所有绘图保存为图像文件而不显示它们,然后在运行python脚本后编写一个html文件来显示所有图像文件。
# 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>
另一个 html 结果页面:
<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>
添加回答
举报