2:
import pandas as pd
import matplotlib.ticker as ticker
import matplotlib.pyplot as plt
dfMonday = pd.read_csv( "0.Mon.csv", encoding = "ISO-8859-1", sep = ';')
dfSlotMean = dfMonday.groupby('slotID', as_index=False).agg( NMonUn=('date', 'nunique'),NMonTot = ('date', 'count'), MeanBPM=('tempo', 'mean') )
#print(dfSlotMean)
dfSlotMean.drop(dfSlotMean[dfSlotMean.NMonUn< 3].index, inplace=True)
df = pd.DataFrame(dfSlotMean)
df.to_csv('1.silMonday.csv', sep = ';', index=False)
print(df)
tick_spacing = 1
fig, ax = plt.subplots(1, 1)
for _, r in df.iterrows():
ax.plot([r['slotID'], r['slotID'] 1], [r['MeanBPM']]*2)
ax.xaxis.grid(True)
ax.xaxis.set_major_locator(ticker.MultipleLocator(tick_spacing))
This is the output i've got:
slotID NMonUn NMonTot MeanBPM
0 7 11 78 129.700564
2 11 6 63 123.372397
3 12 6 33 120.625667
4 13 5 41 124.516341
5 14 4 43 118.904512
6 15 3 13 116.380538
7 16 3 42 119.670881
8 17 5 40 125.424125
9 18 6 45 130.540578
10 19 9 58 128.180172
11 20 5 44 125.596045
I would like to change the thickness of lines based on 'NMonUn' values in order to have thicker lines for higher values and vice versa
CodePudding user response:
You can use the linewidth
parameter and set it to the NMonUN
value
tick_spacing = 1
fig, ax = plt.subplots(1, 1)
for _, r in df.iterrows():
ax.plot([r['slotID'], r['slotID'] 1], [r['MeanBPM']]*2, linewidth=r['NMonUN'])
ax.xaxis.grid(True)
ax.xaxis.set_major_locator(ticker.MultipleLocator(tick_spacing))