SoFunction
Updated on 2024-11-17

python using matplotlib module to plot multiple line graphs, scatter plots

Today I want to visualize the data on the use of the matplotlib module, before a picture of only one curve, and now I want to draw multiple curves on the same picture to compare, the realization is very simple, as follows:

#!usr/bin/env python
#encoding:utf-8
 
'''
__Author__:Yishui Chancheng
Functions: Line Chart, Scatter Chart Testing
'''
 
import random
import matplotlib 
import  as plt 
 
 
def list2mat(data_list,w):
 '''
 Slicing, transposing
 '''
 mat=[]
 res=[]
 for i in range(0,len(data_list)-w+1,w):
 (data_list[i:i+w])
 for i in range(len(mat[0])):
 one_list=[]
 for j in range(len(mat)):
  one_list.append(mat[j][i])
 (one_list)
 return res
 
 
 
def draw_pic_test():
 '''
 Charting
 '''
 data_list=[]
 for i in range(100):
 data_list.append((2,150))
 month_list=range(1,11,1)
 mat=list2mat(data_list,w=10)
 for one_list in mat:
 one_list=[int(one) for one in one_list]
 (month_list,one_list,"x-",label="test_zhexian") 
 ('test_zhexian.png')
 ()
 for one_list in mat:
 one_list=[int(one) for one in one_list]
 (month_list,one_list,marker='x',label='test_sandian',s=30) 
 ('test_sandian.png')
 ()
 
if __name__ == '__main__':
 draw_pic_test()

The results are as follows:

1. Line Chart

2. Scatterplot

Quite interesting.

This is the whole content of this article.