使用for循环在同一图上绘制多个图

问题描述 投票:1回答:1

我想仅使用for循环和matplotlib库在同一张图上绘制c的不同值的x ^ c,每个函数的颜色不同。当我尝试使用for循环时,输出仅显示一个图形。

**** CODE ****

import matplotlib.pyplot as plt
%matplotlib inline
import numpy as np
plt.figure()
x = np.linspace(0,1,100)
for i in range(-10,10,21):
    if i<0:
        plt.plot(x,x**(abs(1/i)))
    elif i>0:
        plt.plot(x,x**i)
plt.show()
python-3.x matplotlib plot jupyter-notebook
1个回答
0
投票

您的range()函数现在仅产生-10的单个值。可能您需要

for i in range(-10,10,1):

产生

enter image description here

© www.soinside.com 2019 - 2024. All rights reserved.