1 回答

TA貢獻1828條經驗 獲得超4個贊
這可能是最簡單的解決方案。其他解決方案可能涉及入侵 Jupyter 的后端環境。
本題涉及并排顯示兩個圖形。
從代碼單元中并排執行的兩個單獨的圖形不起作用。
您將需要創建單獨的圖形,并用于plt.savefig('file.jpg')將每個圖形保存到文件中。
import pandas as pd
import seaborn as sns
import matplotlib.pyplot as plt
# load data
df = sns.load_dataset('penguins', cache=False)
# create and save figure
sns.scatterplot(data=df, x='bill_length_mm', y='bill_depth_mm', hue='sex')
plt.savefig('bill.jpg')
plt.close() # prevents figure from being displayed when code cell is executed
# create and save new figure
sns.scatterplot(data=df, x='flipper_length_mm', y='body_mass_g', hue='sex')
plt.savefig('flipper.jpg')
plt.close() # prevents figure from being displayed when code cell is executed
將圖形保存到文件后,可以通過將它們加載到 Markdown 單元格中并排顯示它們。
如果圖像太大,第二個數字將換行。
然后執行單元格
添加回答
舉報