I am trying to plot data from a Pandas dataframe that is created by importing data from a CSV. However in the plot not every label is displayed along the x-axis, the plot only shows 5 labels along the x-axis.
I have a total of 22 textbased labels, which are all supposed to be shown along the x-axis as tickmarks/labels. These labels correspond to the entries in the column in the dataframe with the name Category.
For each Line in the Line column of the dataframe a separate line in the plot is created. And the Amount columns in the dataframe contains the y-values.
I am sure there is a easy tweak for this, trying ax.set_xticks(np.arange(len(21))
and
plt.xticks( arange(21) )
did not function, maybe because the labels are textbased, not numbers?
EDIT 2
I had some trouble with the initial code after changing computer with another software setup. Now I got another version of the code and CSV that I got to run without problems that actually plots a graph. Now back to the initial problem, as can be seen from the attached picture only a few of the categories (gts, jma, yja, lre, fgg) are displayed as labels along the x-axis (I want all 22 categories to be displayed along the x-axis in full text):
Here is the code that I used for plotting that doesn't display all x-labels:
import pandas as pd
import matplotlib.pyplot as plt
df=pd.read_csv("import.csv",
names=["Category", "Line", "Amount"], encoding="iso-8859-1")
fig, ax = plt.subplots(1,1);
df.groupby("Category").plot(x="Line", y="Amount", ax=ax)
plt.legend([v[0] for v in df.groupby('Category')['Category']], bbox_to_anchor=(1.1, 0.5))
plt.xlabel('Category')
plt.ylabel('Amount')
for line in ax.lines:
line.set_linewidth(0.5)
The CSV contents look as follows, I didn't post the whole file as there are many lines. I believe this should be enough to reproduce the problem (of course I can put more if the plot doesn't work without). The first column is the Line-column, the second column corresponds to the Category-column and the third column corresponds to the Amount-column:
jabber,gts,1
jabber,aed,6
jabber,ame,2
jabber,asy,8
jabber,fxk,1
jabber,jma,6
jabber,oaw,2
jabber,ejt,8
jabber,qat,1
jabber,dzj,6
jabber,yja,2
jabber,ajz,8
jabber,jbp,1
jabber,bvi,6
jabber,pec,2
jabber,lre,8
jabber,wlx,1
jabber,hpw,6
jabber,spg,2
jabber,bdg,8
jabber,fgg,1
jabber,fgz,5
soshy,gts,6
soshy,aed,2
soshy,ame,8
soshy,asy,1
soshy,fxk,6
soshy,jma,2
soshy,oaw,8
soshy,ejt,1
soshy,qat,6
soshy,dzj,2
soshy,yja,8
soshy,ajz,1
soshy,jbp,6
soshy,bvi,2
soshy,pec,8
soshy,lre,1
soshy,wlx,6
soshy,hpw,2
soshy,spg,8
soshy,bdg,1
soshy,fgg,6
soshy,fgz,2