簡體   English   中英

顯示字典中的海洋圖

[英]Showing seaborn plot from dictionary

我需要將圖存儲在這樣的字典中:

import matplotlib.pyplot as plt
import seaborn as sns

test = dict()
test['a'] = sns.lmplot(x="sepal_length", y="sepal_width", hue="species",
                       truncate=True, height=5, data=sns.load_dataset("iris"))

但是,如何從dict顯示該情節呢?

test['a']返回類似於<seaborn.axisgrid.FacetGrid at 0x233011bfe80>的繪圖對象, <seaborn.axisgrid.FacetGrid at 0x233011bfe80>但不顯示繪圖本身。

test['a']
plt.show()

也不顯示圖。

有什么建議如何顯示字典中的情節嗎?

根據給出的答案,我嘗試將dict保存到pickle文件中,但是顯示pickle中的圖會出現錯誤:

import pickle
import matplotlib.pyplot as plt
import seaborn as sns

test = dict()
test['a'] = sns.lmplot(x="sepal_length", y="sepal_width", hue="species",
                       truncate=True, data=sns.load_dataset("iris"))
plt.close()

# store dict in pickle file
outfile = open('test.pkl', 'wb')
pickle.dump(test, outfile)
outfile.close()

# delete dictionary
del test

# load dictionary form pickle file
infile = open('test.pkl', 'rb')
test = pickle.load(infile)
infile.close()

test['a'].fig

調用相關的fig似乎就足夠了:

test['a'].fig

在Jupyter筆記本中為我工作。

順便說一句:必須刪除高度參數

完全改變問題不是很好。 但是,看來您的問題僅與木星有關! 檢查此問題

一種解決方案是在第一個單元格前添加%matplotlib notebook

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM