简体   繁体   English

在 Python 中用不同颜色在同一张图上绘制 n 个不同的图

[英]Plot n different graphs on the same plot with different colors in Python

I would like to plot n different graphs on the same plot with different color.我想在同一个图上用不同的颜色绘制 n 个不同的图。 The problem I got is that I get lines between the different plots, and I don't get random color on the graph.我遇到的问题是我在不同的图之间得到了线条,而且我没有在图表上得到随机颜色。 I'm an beginner.我是初学者。

My Plot:我的剧情:

阴谋

My Code:我的代码:

import matplotlib.pyplot as plt 
import random
import numpy

list_y = []
list_x = []
counter = 0

# generate data
for i in range(0,5):
    for p in range(0,10):
        list_y.append(random.uniform(0.9,1.2))
         counter=counter+1
         list_x.append(counter)
         print(list_y)
         print(list_x)
    plt.plot(list_x, list_y,c=numpy.random.rand(3,)) 
    counter = 0

# naming the x axis 
plt.xlabel('x - axis') 
# naming the y axis 
plt.ylabel('y - axis') 

# giving a title to my graph 
plt.title('My first graph!') 

# function to show the plot 
plt.show() 

You just misplaced the initialisations你只是放错了初始化

list_y=[]
list_x=[]

before the line for i in range(0,5): rather than after it, hence finally a plot with the points of all 5 graphs is drawn over the preceding ones.for i in range(0,5):的线之前而不是在它之后,因此最终在前面的图形上绘制了包含所有 5 个图形的点的图。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM