l would like to plot in the same plot labels_train ans labels_test distribution in the same plot. l have 101 classes (string) to be shonwn in the x-axis. Since there are strings l got the following error :
ValueError: could not convert string to float: 'sitdown'
at the following line code :
ax1.plot(labels, values, label=' train classes')
Here is my code :
import matplotlib.pyplot as plt
from collections import Counter
def make_plot(train_labels,test_labels):
labels2, values2 = zip(*Counter(test_labels).items())
print("labels ", labels2)
print("lvalues", values2)
labels, values = zip(*Counter(train_labels).items())
print("labels ", labels)
print("lvalues", values)
fig1, ax1 = plt.subplots()
ax1.plot(labels, values, label=' train classes')
ax1.plot(labels2, values2, label=' test classes')
ax1.set_xlabel("classes")
ax1.set_ylabel("number of examples")
ax1.set_title("data distibution")
ax1.legend(loc='best')
fig1.show()
EDIT
l updated my conda environment to get matplotlib 2.1 as suggested by @ ImportanceOfBeingErnest.
However l get a disordered plot
so l did the following to reorder the labels.
lists = sorted(zip(*[labels2, values2]))
labels2, values2 = list(zip(*lists))
lists2 = sorted(zip(*[labels, values]))
labels2, values2 = list(zip(*lists2))
labels=['Typing', 'Surfing', 'CricketBowling', 'JugglingBalls', 'BoxingSpeedBag',...]
lvalues=[46, 38, 39, 34, 40,...]
labels2=['Rafting', 'Punch', 'ApplyEyeMakeup', 'JumpRope', 'PlayingDhol',...]
lvalues2=[78, 112, 106, 105, 116,...]
But is still doesn't make sense. I need to get the same order of labels to share the x-axis between the two plot.
rotation='vertical' within ax1.plot() is not accepted as in
plt.xticks(rotation='vertical')