![](/img/trans.png)
[英]Converting one large figure into several smaller figures using Pythons Matplotlib
[英]Change style in one Matplotlib Figure when working with several Figures simultaneously
假設我在for循環中同時更新了2個Matplotlib數字。 其中一個圖(假設fig0
有圖像,而fig1
是線圖)。 我想fig0
有標准Matplotlib風格,同時在fig1
我想設置plt.style.use('ggplot')
為fig1
。
到目前為止,我試過這個:
plt.style.use('ggplot')
fig0 = plt.figure(0)
fig1 = plt.figure(1)
for i in range(10):
# print stuff in both figures
但是這在兩個圖中都設置了ggplot
樣式(如預期的那樣)。 我找不到在每個圖中單獨設置樣式的方法。
除了循環之外,這將解決它。
import matplotlib.pyplot as plt
with plt.style.context('ggplot'):
plt.figure(0)
plt.plot([3,2,1])
with plt.style.context('default'):
plt.figure(1)
plt.plot([1,2,3])
plt.show()
無論如何,你可能會在沒有循環的情況下變得更好......因為循環因某種原因並不是絕對必要的。 只需保留您在列表循環中添加的圖表並修改上面的示例。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.