I have the following code (removed most of the fluff for brevity):
# Assign 'aInf' to the DataFrame called 'dfDis'
dfDis = pd.DataFrame(aDis, columns=cols)
dfDis.columns = ['Year', 'Type', 'Total']
try:
dfDisB = pd.pivot_table(dfDis, index=['Year'], columns = ['Type'],aggfunc= 'sum',fill_value=0)
dfDisB.columns = [x[1] for x in dfDisB.columns]
dfDisC = dfDisB.fillna(0)
dfFinalDis = dfDisC.reindex(dfDisC.sum().sort_values(ascending=False).index, axis=1)
# This is a dictonary of dissemination with a colour assigned to it
colorDict = {**** cut ****}
# Change the font
plt.rcParams["font.family"] = "Gill Sans MT"
axDis = dfFinalDis.plot.bar(stacked=True, color=[colorDict.get(x, '#333333') for x in dfFinalDis.columns],
figsize=(10, 8))
plt.legend(loc='upper right', bbox_to_anchor=(0.6, -0.3), frameon=False)
plt.title(items1)
# Hide the spines
for spine in axDis.spines:
axDis.spines[spine].set_visible(False)
# Hide the tick marks
axDis.tick_params(axis=u'both', which=u'both', length=0)
# Move the x label down slightly
axDis.xaxis.labelpad = 25
# Make new folder
newpath = r'C://Users//{}//Desktop//{}_RFPlots'.format(staName2, itemsGraph)
if not os.path.exists(newpath):
os.makedirs(newpath)
# Show plot
plt.savefig('C://Users//{}//Desktop//{}_RFPlots//Dissemination.png'.format(staName2, itemsGraph), bbox_inches='tight')
It produces this:
On the x-axis, the 'invalid' label is being cut off, which is weird as I have about 10 or so charts being produced, and none of the rest are doing it.
I have tried this link: Why is my xlabel cut off in my matplotlib plot?
And none of the solutions are working.
As I am writing this, I am thinking maybe it is do to with it matching the length of the other columns i.e. 4 digits long, but I am not setting the length anywhere, and as mentioned, I have other charts working fine.
Any help would be much apprecaited