![](/img/trans.png)
[英]Matplotlib: plot multiple graphs as subplots on the same figure when different functions in the same class call the plot routine?
[英]How to plot multiple functions on the same figure, in Matplotlib?
如何在同一個圖中在域t
上繪制以下 3 個函數(即sin
、 cos
和加法)?
from numpy import *
import math
import matplotlib.pyplot as plt
t = linspace(0, 2*math.pi, 400)
a = sin(t)
b = cos(t)
c = a + b
要在同一個圖形上繪制多個圖形,您必須執行以下操作:
from numpy import *
import math
import matplotlib.pyplot as plt
t = linspace(0, 2*math.pi, 400)
a = sin(t)
b = cos(t)
c = a + b
plt.plot(t, a, 'r') # plotting t, a separately
plt.plot(t, b, 'b') # plotting t, b separately
plt.plot(t, c, 'g') # plotting t, c separately
plt.show()
只需使用函數plot
如下
figure()
...
plot(t, a)
plot(t, b)
plot(t, c)
如果你想使用圖形,我舉一個例子,你想在同一個圖形中繪制多條 ROC 曲線:
from matplotlib import pyplot as plt
plt.figure()
for item in range(0, 10, 1):
plt.plot(fpr[item], tpr[item])
plt.show()
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.