I want to draw this type of graph below based on data in excel. In this way, I don't need to download the excel file from the server every time to generate it.
plt.switch_backend('Agg')
plt.subplots_adjust(right = 0.98, top = 0.96, bottom=0.3,left=0.1)
ax = plt.gca()
ipc = range(1,7)
x = np.arange(0,len(ipc))
print(x)
ax.bar(x,ipc, edgecolor="b", width=0.3)
xmajorLocator = FixedLocator(np.arange(-0.5,len(ipc),2))
# xmajorFormatter = FormatStrFormatter(major)
xminorLocator = FixedLocator(range(0,len(ipc),1))
ax.xaxis.set_minor_locator(xminorLocator)
ax.xaxis.set_major_locator(xmajorLocator)
types=["apple","banana"]
times=["past","now","future"]
# plt.setp(ax.xaxis.get_majorticklabels(), rotation=90, fontsize=10)
plt.setp(ax.xaxis.get_minorticklabels(), rotation=90, fontsize=8)
add = lambda x,pos:types[pos%2]
sub = lambda x,pos:times[pos%3]
ax.xaxis.set_minor_formatter(add)
ax.xaxis.set_major_formatter(sub)
plt.xlim(-1,7)
ax.tick_params(axis ='x', which ='minor',pad = 0,
labelsize = 8, colors ='b')
ax.tick_params(axis ='x', which ='major', pad = 10, length=30, width=0.35,
labelsize = 20, colors ='k', )
By setting major and minor ticks, I achieved the result below. But what I want is that the labels of the major ticks should be in the middle of each set of minor ticks. How should I adjust it?
Or is there a better way to achieve the above functionality?