2 回答

TA貢獻(xiàn)1966條經(jīng)驗(yàn) 獲得超4個(gè)贊
我不知道是否可以模擬 jupyter 筆記本,而無需實(shí)際運(yùn)行它。
另一種方法是使用webagg后端。在這種情況下,只plt.show()在末尾放置一個(gè)調(diào)用以在同一頁面上顯示所有三個(gè)數(shù)字。
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()
運(yùn)行此程序時(shí),應(yīng)打開一個(gè)瀏覽器窗口,并顯示三個(gè)數(shù)字

TA貢獻(xiàn)1831條經(jīng)驗(yàn) 獲得超9個(gè)贊
將所有繪圖保存為圖像文件而不顯示它們,然后在運(yùn)行python腳本后編寫一個(gè)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>
另一個(gè) html 結(jié)果頁面:
<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>
添加回答
舉報(bào)