Skip to content

Instantly share code, notes, and snippets.

@suncle1993
Last active November 13, 2017 05:50
Show Gist options
  • Save suncle1993/343aac6ba3399c8296bbab8611b0fbca to your computer and use it in GitHub Desktop.
Save suncle1993/343aac6ba3399c8296bbab8611b0fbca to your computer and use it in GitHub Desktop.
pyplot在一个图中画多条线的方式
#!/usr/bin/env python
# -*- coding: utf-8 -*-
import sys
reload(sys)
sys.setdefaultencoding('utf-8')
import matplotlib
# matplotlib.use('Agg')
import numpy as np
import matplotlib.pyplot as plt
import matplotlib.dates as mdate
import pylab as pl
import datetime
import time
def draw_total(time_list1, bandwidth1, time_list2, bandwidth2):
pl.plot(time_list1, bandwidth1, 'r', label='bandwidth1')
pl.plot(time_list2, bandwidth2, 'g', label='bandwidth2')
pl.xlabel('time axis')
pl.ylabel('bandwidth axis')
pl.gca().xaxis.set_major_formatter(mdate.DateFormatter('%H'))
pl.grid(True)
pl.legend(loc='upper left')
pl.show()
while True:
time.sleep(1)
def new_time_list(time_list):
new_times = []
for time_str in time_list:
new_times.append(datetime.datetime.strptime(time_str, '%Y-%m-%d %H:%M:%S'))
return new_times
if __name__ == '__main__':
draw_total(new_time_list(["2017-11-3 12:11:12", "2017-11-3 13:11:12", "2017-11-3 14:11:12"]),
[12, 234, 234],
new_time_list(["2017-11-3 12:11:12", "2017-11-3 13:11:12", "2017-11-3 14:11:12"]),
[224, 55, 33])
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment