I have this two Dataset to plot:
lwm:
Client name,CTR,mean_diff
customeronewithverylongname,0.08355714285714286,-0.02935714285714286
customertwowithverylongname,0.028471428571428568,-0.001942857142857142
customerthree,0.014371428571428571,0.000700000000000001
customerfourwithverylongname,0.09971428571428573,0.0014285714285714457
customerfive,0.006799999999999999,0.0014999999999999987
customersixQuickSale,0.0396,0.005075000000000003
customerseven,0.16254285714285713,0.0052428571428571324
pwm:
Client name,CTR,mean_diff
customeronewithverylongname,0.11291428571428572,-0.02935714285714286
customertwowithverylongname,0.03041428571428571,-0.001942857142857142
customerthree,0.01367142857142857,0.000700000000000001
customerfourwithverylongname,0.09828571428571428,0.0014285714285714457
customerfive,0.0053,0.0014999999999999987
customersixQuickSale,0.034525,0.005075000000000003
customerseven,0.1573,0.0052428571428571324
I want to plot a series of histograms with the name of the customers on the x axis and CTR on the y, without the xlabels cut off.
I plotted and noticed that xlabels where cut off. So I read this question and solved this way:
plt.subplots_adjust(left=None, bottom=0.15, right=None, top=None, wspace=None, hspace=None)
I tried with different values of bottom
:
0.10
0.15
0.17
0.25
0.30
0.35
and each time the xlabels changed position, i had never the same order for the xlabels.
Instead the histograms are always in the same position.
bottom=0.15
This is a snippet of my code
#defing the labels of the histograms
#pwm and lwm are the last & penultimate week dataframes
# with the weekly mean CTR for each customer
#defing the labels of the histograms
customer_list=set(lwm['Client name'])
x_pos=list(range(len(customer_list)))
x_lab=customer_list
width=0.4
#defining the y max heigh
max_y=max(zip(lwm['CTR'],pwm['CTR']))
#defining the histograms
fig,ax =plt.subplots(figsize=(8,6))
plt.bar(x_pos, pwm['CTR'], width, alpha=0.5, color='b',label=x_lab)
plt.bar([p + width for p in x_pos], lwm['CTR'], width, alpha=0.5, color='r', label=x_lab)
#defining the y max height
plt.ylim([0,max(max_y[0],max_y[1])*1.1])
plt.xticks(x_pos,x_lab,rotation=45, rotation_mode="anchor", ha="right")
plt.title('CTR Bar plot of the last week')
# Adding the legend and showing the plot
plt.legend(['Penultimate Week CTR','Last Week CTR', ], loc='best')
plt.subplots_adjust(left=None, bottom=0.15, right=None, top=None, wspace=None, hspace=None)
plt.show()
I don't knwow if i have to insert more information about the dataset or if it is fine
I am self tough, I read the documentation here and this question and this to. But i still did not come out with a solution.