JavaScript
x
20
20
1
import pandas as pd
2
import matplotlib.pyplot as plt
3
4
def csv_til_liste(filnavn):
5
occuDF = pd.read_csv(filnavn)
6
occuList=occuDF.values.tolist()
7
return occuDF, occuList
8
9
10
occuDF, occuList = csv_til_liste("occupancy.csv")
11
plt.figure(1)
12
occuDF.boxplot(column = 'Temperature', by = 'Occupancy')
13
plt.suptitle('')
14
15
x=(1, 2, 3, 4, 5)
16
y=(1,2,3,4,5)
17
plt.figure(2)
18
plt.plot(x,y)
19
plt.show()
20
When I run the program, the two plots are plotted in one figure, but I want them in two separate figures.
Advertisement
Answer
The pandas.DataFrame.boxplot
takes an ax parameter, as written in the docs.
So you can use:
JavaScript
1
15
15
1
fig1 = plt.figure()
2
ax1 = fig1.add_subplot(1, 1, 1)
3
occuDF.boxplot(column = 'Temperature', by = 'Occupancy', ax=ax1)
4
plt.suptitle('')
5
6
x=(1, 2, 3, 4, 5)
7
y=(1,2,3,4,5)
8
9
fig2 = plt.figure(2)
10
ax2 = fig2.add_subplot(1, 1, 1)
11
ax2.plot(x,y)
12
13
plt.show()
14
15
Otherwise, you can plot in different subplots of the same figure by applying minimal changes.