from datetime import datetime
import datetime as dt
import csv
import matplotlib.dates as mdates
import numpy as np
import matplotlib.pyplot as plt
ldays = list()
aesvalues = list()
tezvalues = list()
vdevalues = list()
with open('data/dg_year_50.csv', newline='') as csvfile:
has_header = csv.Sniffer().has_header(csvfile.read(1024))
csvfile.seek(0) # Rewind.
datareader = csv.reader(csvfile, delimiter=',', quotechar='|')
if has_header:
next(datareader) # Skip header row.
for row in datareader:
date_cell = row[0]
aes_cell = row[1]
tez_cell = row[2]
vde_cell = row[3]
datetime_object = datetime.strptime(date_cell, '%d.%m.%Y %H:%M:%S')
aesvalues.append(aes_cell)
tezvalues.append(tez_cell)
vdevalues.append(tez_cell)
ldays.append(datetime_object)
days = mdates.date2num(np.array(ldays))
s_aesvalues = sorted(list(map(int, aesvalues)))
s_tezvalues = sorted(list(map(int, tezvalues)))
s_vdevalues = sorted(list(map(int, vdevalues)))
# These are the colors that will be used in the plot
color_sequence = ['#ffbb78', '#e377c2', '#1f77b4', '#ff7f0e', '#2ca02c',
'#98df8a', '#d62728', '#ff9896', '#9467bd', '#c5b0d5',
'#8c564b', '#c49c94', '#aec7e8', '#e377c2', '#f7b6d2',
'#c7c7c7', '#bcbd22', '#dbdb8d', '#17becf', '#9edae5']
# make a plot
fig, ax = plt.subplots(figsize=(14, 12))
# plot the data
majors = [s_tezvalues, s_vdevalues, s_aesvalues]
for rank, column in enumerate(majors):
line = plt.plot_date(x=days, y=majors[rank], lw=2.5, color=color_sequence[rank])
fig.suptitle('Дані по енергетиці', fontsize=18, ha='center')
plt.xlabel('Дата', fontsize=14, ha='center')
plt.ylabel('Кількість енергії (Вт)', fontsize=14, ha='center')
plt.show()
我有4列(Дата,АЕС,ТЕЦ,ВДЕ)“ data / dg_year_50.csv”。 第一个代表“日期”,其余三个代表需要以图表中的线形式显示的适当值。 我不明白为什么我要显示2行而不是3行。 结果可视化看起来像这样:
答案 0 :(得分:0)