如何在Matplotlib中绘制同一个图上的多个函数? [英] How to plot multiple functions on the same figure, in Matplotlib?

查看:3336
本文介绍了如何在Matplotlib中绘制同一个图上的多个函数?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我怎么能在这个域上绘制以下3个函数(即 sin cos 以及加法) t ,在同一数字上?

How could I plot the following 3 functions (i.e. sin, cos and the addition), on the domain t, on the same figure?

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


推荐答案

在同一张图上绘制多张图,您需要做:

To plot multiple graphs on the same figure you will have to do:

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()

这篇关于如何在Matplotlib中绘制同一个图上的多个函数?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆