簡體   English   中英

在同時處理多個圖形時,在一個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.

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