Skip to content Skip to sidebar Skip to footer

Line Thickness In Pyplot Graph Based On A Dataframe Column

First, the dataframe: And I want to create a line graph. I want one line per category and on the x-axis I want the date, and on the y-axis the 12MKG. I also want every line to hav

Solution 1:

I came up with something like this:

import matplotlib.pylab as pl
import matplotlib.pyplot as plt

labels = set(df['categorie'].values)
colors = pl.cm.jet(np.linspace(0,1,len(labels)))
width_lines = df.amount.values
for key, color, width in zip(labels, range(len(labels)), width_lines):
    data_x = df.loc[df['categorie']==key]['date']
    data_y = df.loc[df['categorie']==key]['12MKG']
    width = df.loc[df['categorie']==key]['amount']
    width = sum(width)
    plt.plot(data_x, data_y, color=colors[color], label=key, linewidth=width/100)
plt.legend()
plt.show()

The problem is that I'm not sure what the range of the amount values is. If simple division doesn't match your case, you can try to first aggregate all values and then adjust the range.


Post a Comment for "Line Thickness In Pyplot Graph Based On A Dataframe Column"