python绘制不带颜色曲线图_在Python MatPlotLib中使用动画时如何更改绘制曲线的颜色?...

您必须存储绘图返回的线条实例并在再次绘制之前调用set_color(颜色):

import numpy as np

import matplotlib.pyplot as plt

import matplotlib.animation as animation

import random

# an empty variable, whre we store the returned line of plot:

line = None

fig = plt.figure()

ax1 = fig.add_subplot(1,1,1)

def main(i):

# we have to make line global:

global line

# Actual parameters

A0 = 10

K0 = random.uniform(-15,-1)

C0 = random.uniform(0,10)

# Generate some data based on these

tmin, tmax = 0, 0.5

num = 20

t = np.linspace(tmin, tmax, num)

y = model_func(t, A0, K0, C0)

# check if line already exists, if yes make it gray:

if line is not None:

line.set_color('gray')

# plot returns a list with line instances, one for each line you draw,

# the comma is used to unpack the one element list

line, = ax1.plot(t,y, color='red')

def model_func(t, A, K, C):

return A * np.exp(K * t)

ani = animation.FuncAnimation(fig, main, interval=1000)

plt.show()

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值