Search code examples
pythonpandasmatplotlibplotaxis-labels

plot dataframe kind= line with axis labels


I already asked about labeling the axes and I have got the answer that satisfied me for the data that I had at that time. But now I'm trying plot the dataframe with kind=line to see better the evaluation of my values. so I'm using these pandas methods, that don't work in the same manner for kind=line as for kind=bar, and though don't provide the labels for axes. So my dataframe :

    name          Homework_note    Class_note     Behavior_note
    Alice Ji      7                6                 6
    Eleonora LI   2                5                 4
    Mike The      6                5                 3
    Helen Wo      5                3                 5

the script I use:

    df=pd.read_csv(os.path.join(path,'class_notes.csv'), sep='\t|,',  engine='python')
    df.columns=['name', 'Homework_note', 'Class_note', 'Behavior_note']
    ax=df.plot(kind='line', x='name', color=['red','blue', 'green'], figsize=(400,100))
    ax.set_xlabel("Names", fontsize=56)
    ax.set_ylabel("Notes", fontsize=56) 
    ax.set_title("Notes evaluation", fontsize=79)
    plt.legend(loc=2,prop={'size':60})
    plt.savefig(os.path.join(path,'notes_names.png'), bbox_inches='tight', dpi=100)

What else can I add to put labels on the axes (both x and y)? I prefer to stay with these pandas methods, cause I find them more comfortable to work with dataframes, but I haven't found the way to put the labels while using this type of plot line.


Solution

  • The labels will show up for a smaller figsize (in inches!). For the the legend, take a look here