我有一个 python 代码,它使用 mpld3 save_html 方法将条形图存储为 html 文件。但是,当我渲染 html 文件时,条形图在顶部显示 x 轴刻度,如下所示。
我根本不希望显示刻度,也没有刻度标签,但希望底部的 x 轴线。我以为我已经采取了必要的步骤来防止这种情况发生。请看下面的代码。我将不胜感激这里的任何帮助。我正在消隐。
fig1,ax1=plt.subplots()
dsize=fig1.get_size_inches()
fig1.set_size_inches((dsize[0]/2)*(1.5),(dsize[1]/2)*(1.25))
m_colors= ['red','green','blue','yellow','black','cyan','aqua','brown','coral','magenta','khaki','indigo','lavender','navy','olive','pink','plum','teal','tan','violet','wheat','orchid']
bucket=['apple','banana','orange','lemon','pineapple']
counts=[10,20,5,16,2]
rects = ax1.bar(bucket,counts,color=m_colors)
ax1.set_xlabel('Service Types')
ax1.set_ylabel('Anomalous Flow per Service Type')
ax1.tick_params(axis='x',which='both',bottom='off',top='off',labelbottom='off')
ax1.xaxis.set_label_position('bottom')
for rect in rects:
height = rect.get_height()
ax1.text(rect.get_x() + rect.get_width()/2., 1.05*height,
'%d' % int(height),
ha='center', va='bottom')
#leg=ax1.legend((rects),(unique))
legend_font_props = FontProperties()
legend_font_props.set_size('xx-small')
leg=ax1.legend((rects),(bucket),loc='upper right',prop=legend_font_props)
mpld3.save_html(fig1,"test.html")