gpt4 book ai didi

python - Matplotlib 简单的不同颜色线条图

转载 作者:太空宇宙 更新时间:2023-11-04 11:15:21 24 4
gpt4 key购买 nike

<分区>

我有一个非常简单的 matplot 图,我想更改线条颜色,当数据高于 50 时,线条将变为红色,低于 50 时,线条颜色将为绿色。

如何更改线条颜色,目前我使用 plot 加载 x 和 y 数据然后显示图形。

我尝试了两种将数据加载到图表中的方法,但它们都不起作用,也无法弄清楚我们要用看起来如此简单的东西做什么。

# ==========================
# First try at the changing the line colour

import matplotlib.pyplot as plt
import pandas as pd

for i in range(0,100):
if (i>50):
plt.plot(i,i, color = 'r') #plot red line
if (i<49):
plt.plot(i,i, color = 'g') #plot red line

plt.show()

# ==========================
# Second try at the changing the line colour

for i in range(0,50):
x.append(i)
y.append(i)

plt.plot(x,y, color='green')

for i in range(50,100):
x.append(i)
y.append(i)

plt.plot(x,y, color='red')
plt.show()

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com