forked from gzavo/CS_Assignment_old
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathplot.py
More file actions
33 lines (24 loc) · 918 Bytes
/
plot.py
File metadata and controls
33 lines (24 loc) · 918 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
import pandas as pd
import matplotlib.pyplot as plt
import numpy as np
df = pd.read_csv('istherecorrelation.csv', sep = ';')
df["WO [x1000]"]=df["WO [x1000]"].str.replace(',','.')
df["WO [x1000]"]=pd.to_numeric(df["WO [x1000]"],errors = 'coerce')
fig, ax1 = plt.subplots()
x = df['Year']
y1 = df['WO [x1000]']
y2 = df['NL Beer consumption [x1000 hectoliter]']
color = 'tab:red'
ax1.set_xlabel('Year')
ax1.set_ylabel('WO [x1000]', color=color)
ax1.plot(x, y1, color=color)
ax2 = ax1.twinx() # instantiate a second axes that shares the same x-axis
color = 'tab:blue'
ax2.set_ylabel('Beer consumption [x1000 hectoliter]', color=color) # we already handled the x-label with ax1
ax2.plot(x, y2, color=color)
fig.tight_layout() # otherwise the right y-label is slightly clipped
plt.show()
fig.savefig('Beer consumption and WO.jpg',
format='jpeg',
dpi=300,
bbox_inches='tight')