python绘图 | python绘制静态图 | python绘制动态图

 静态绘图

import matplotlib.pyplot as plt

x = [1, 2, 3]
y = [1, 2, 3]
y1 = [4, 5, 6]

plt.plot(x, y, color='green', marker='o', linestyle='dashed', linewidth=2, markersize=12)
plt.plot(x, y1, color='red', marker='*', linestyle='solid', linewidth=2, markersize=12)
plt.show()

动态绘图

import matplotlib.pyplot as plt
import numpy as np

class DataPlot:
	'''绘图
	'''
	def __init__(self,figureNum=1):
		self.figureNum = figureNum
		self.subplotNum = 211
		self.isFirst_DrawOneGraph = 1
		self.color = ['b','g','r','c','m','y','k','tan']

	def DrawOneGraph(self,DataList_x,DataList_y,LabelList):  
		'''在一幅图中绘制,
		DataList_x: x轴数据列表
        DataList_y: y轴数据列表
		LabelList: 标签列表
		'''
		if self.isFirst_DrawOneGraph :
			self.isFirst_DrawOneGraph = 0
			self.DataListNum = len(DataList_y)
			self.DataList_x = np.zeros([self.DataListNum,2])
			self.DataList_y = np.zeros([self.DataListNum,2])
			plt.ion()
			plt.figure(self.figureNum)			
			plt.grid()
			for i in range(0,self.DataListNum):	
			    ##### 横坐标 #####
				self.DataList_x[i][0] = DataList_x[i]
				self.DataList_x[i][1] = DataList_x[i]                
			    ##### 纵坐标 #####
				self.DataList_y[i][0] = DataList_y[i]
				self.DataList_y[i][1] = DataList_y[i]
				plt.plot(self.DataList_x[i], self.DataList_y[i],linestyle='-',color=self.color[(i)%len(self.color)],label=LabelList[i])
				plt.legend(loc='upper right')
		for i in range(0,self.DataListNum):
            ##### 横坐标 #####
			self.DataList_x[i][0] = self.DataList_x[i][1]
			self.DataList_x[i][1] = DataList_x[i]
            ##### 纵坐标 #####
			self.DataList_y[i][0] = self.DataList_y[i][1]
			self.DataList_y[i][1] = DataList_y[i]
			plt.figure(self.figureNum)
			plt.plot(self.DataList_x[i], self.DataList_y[i],linestyle='-',color=self.color[(i)%len(self.color)])
			plt.pause(0.001)

	def DrawMultipleGraphs(self,DataList_x,DataList_y,LabelList):
		print(1)



if __name__ == '__main__':

    Graph = DataPlot(0)
    for i in np.arange(0, 100):
        y1 = i
        y2 = 2*i

        xList = [ i, i ]
        yList = [ y1, y2 ]
        labelList = ['y1','y2']
        Graph.DrawOneGraph( xList, yList, labelList)

    

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

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值