gpt4 book ai didi

python - 如何强制 matplotlib 在 Y 轴上只显示整数

转载 作者:太空狗 更新时间:2023-10-29 22:11:10 26 4
gpt4 key购买 nike

<分区>

我正在可视化的数据只有在整数时才有意义。

即就我正在分析的信息的上下文而言,0.2 条记录没有意义。

如何强制 matplotlib 在 Y 轴上只使用整数。 IE。 1、100、5 等?不是 0.1、0.2 等

for a in account_list:
f = plt.figure()
f.set_figheight(20)
f.set_figwidth(20)
f.sharex = True
f.sharey=True

left = 0.125 # the left side of the subplots of the figure
right = 0.9 # the right side of the subplots of the figure
bottom = 0.1 # the bottom of the subplots of the figure
top = 0.9 # the top of the subplots of the figure
wspace = 0.2 # the amount of width reserved for blank space between subplots
hspace = .8 # the amount of height reserved for white space between subplots
subplots_adjust(left=left, right=right, bottom=bottom, top=top, wspace=wspace, hspace=hspace)

count = 1
for h in headings:
sorted_data[sorted_data.account == a].ix[0:,['month_date',h]].plot(ax=f.add_subplot(7,3,count),legend=True,subplots=True,x='month_date',y=h)

#set bottom Y axis limit to 0 and change number format to 1 dec place.
axis_data = f.gca()
axis_data.set_ylim(bottom=0.)
from matplotlib.ticker import FormatStrFormatter
axis_data.yaxis.set_major_formatter(FormatStrFormatter('%.0f'))

#This was meant to set Y axis to integer???
y_formatter = matplotlib.ticker.ScalarFormatter(useOffset=False)
axis_data.yaxis.set_major_formatter(y_formatter)

import matplotlib.patches as mpatches

legend_name = mpatches.Patch(color='none', label=h)
plt.xlabel("")
ppl.legend(handles=[legend_name],bbox_to_anchor=(0.,1.2,1.0,.10), loc="center",ncol=2, mode="expand", borderaxespad=0.)
count = count + 1
savefig(a + '.png', bbox_inches='tight')

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com