I needed to make a plot using pandas
and matplotlib
. I am using python3.9
and tried the code in IPython
. The matplotlib
version is 3.3.2, and that of pandas
1.1.5. What I get, is unreadable text showed in the terminal with no plot being generated. Here is the code:
#Three lines to make the compiler able to draw:
import sys
import matplotlib
matplotlib.use('Agg')
import pandas as pd
import matplotlib.pyplot as plt
df = pd.read_csv('data.csv')
df["Duration"].plot(kind = 'hist')
plt.show()
#Two lines to make the compiler able to draw:
plt.savefig(sys.stdout.buffer)
sys.stdout.flush()
What is the reason behind ?