Following up from a previous question, I am confused by how matplotlib.pyplot works. I have a DataFrameGroupBy object with multiple groups, and I want to make a single figure with multiple functions (one per group). My research indicates that the following code should essentially yield one figure with multiple lines:
import pandas as pd
import matplotlib.pyplot as plt
with open("data.csv", encoding='utf-8') as datei:
df = pd.read_csv(datei, sep=';')
groups = df.groupby(['A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K',
'L', 'M', 'N', 'O', 'P', 'Q']) # Columns from A-Q are distinctive as a unit
for element, group in groups: # Looping over the GroupBy objects
group.plot(x='R', y='X') # Columns R and X contain the x- and y-axis values respectively
# According to SO answers, calling .plot() should not create a graph until the graph itself is called
plt.show()
Instead, I am getting multiple graphs with one line each. Following some instructions, I tried shoving plt.ion()
, plt.ioff()
, and plt.pause(0.5)
in all possible places that I could think of, but I don't quite understand how they work, so I might have not done it correctly.