import pandas as pd import matplotlib.pyplot as plt def csv_til_liste(filnavn): occuDF = pd.read_csv(filnavn) occuList=occuDF.values.tolist() return occuDF, occuList occuDF, occuList = csv_til_liste("occupancy.csv") plt.figure(1) occuDF.boxplot(column = 'Temperature', by = 'Occupancy') plt.suptitle('') x=(1, 2, 3, 4, 5) y=(1,2,3,4,5) plt.figure(2) plt.plot(x,y) plt.show()
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:
fig1 = plt.figure() ax1 = fig1.add_subplot(1, 1, 1) occuDF.boxplot(column = 'Temperature', by = 'Occupancy', ax=ax1) plt.suptitle('') x=(1, 2, 3, 4, 5) y=(1,2,3,4,5) fig2 = plt.figure(2) ax2 = fig2.add_subplot(1, 1, 1) ax2.plot(x,y) plt.show()
Otherwise, you can plot in different subplots of the same figure by applying minimal changes.