我有一个包含分位数的小型 Pandas 数据框,我想通过条形图绘制它们。虽然出现在 Pandas 数据框索引上的分位数在绘制时被四舍五入为 2 个十进制数字,但出现多个十进制数字,这使得绘图变得丑陋。如何将 xtick 标签四舍五入为 2 位十进制数字?
对于一个可重现的示例,我提供了数据、代码和生成的图。
plot_data.to_json()
'{"(\'price\', \'cu2003\')":{"0.0":0.0,"0.05":0.0,"0.1":0.0,"0.15000000000000002":0.0,"0.2":0.0,"0.25":0.0108436348,"0.30000000000000004":0.0216146115,"0.35000000000000003":0.0216755175,"0.4":0.0218316778,"0.45":0.0219418541,"0.5":0.0220531481,"0.55":0.0325273772,"0.6000000000000001":0.0433041031,"0.65":0.0437588885,"0.7000000000000001":0.0441111601,"0.75":0.0561041293,"0.8":0.0657966882,"0.8500000000000001":0.08670207,"0.9":0.110314396,"0.9500000000000001":0.1924818841,"1.0":0.5920403465},"(\'price\', \'cu2004\')":{"0.0":0.0,"0.05":0.0,"0.1":0.0,"0.15000000000000002":0.0,"0.2":0.0,"0.25":0.0215354797,"0.30000000000000004":0.02159594,"0.35000000000000003":0.0217367677,"0.4":0.0218221495,"0.45":0.0219514872,"0.5":0.02236386,"0.55":0.0431825542,"0.6000000000000001":0.0435492651,"0.65":0.0438260107,"0.7000000000000001":0.0449387709,"0.75":0.065267051,"0.8":0.0666592601,"0.8500000000000001":0.0876136239,"0.9":0.1118193,"0.9500000000000001":0.1999777802,"1.0":0.7091412742},"(\'price\', \'cu2005\')":{"0.0":0.0,"0.05":0.0,"0.1":0.0,"0.15000000000000002":0.0,"0.2":0.0107388316,"0.25":0.0214569252,"0.30000000000000004":0.0215354797,"0.35000000000000003":0.0216896215,"0.4":0.0217841194,"0.45":0.0219178082,"0.5":0.0323275862,"0.55":0.0430338892,"0.6000000000000001":0.0434074878,"0.65":0.0437301848,"0.7000000000000001":0.0537172325,"0.75":0.0649420933,"0.8":0.0664378253,"0.8500000000000001":0.0871934605,"0.9":0.1107787748,"0.9500000000000001":0.1994901917,"1.0":0.7296849088},"(\'price\', \'cu2006\')":{"0.0":0.0,"0.05":0.0,"0.1":0.0,"0.15000000000000002":0.0,"0.2":0.0107596299,"0.25":0.0109075044,"0.30000000000000004":0.0214615302,"0.35000000000000003":0.0215308429,"0.4":0.0217556837,"0.45":0.0221116639,"0.5":0.0324815938,"0.55":0.0332299513,"0.6000000000000001":0.0430848772,"0.65":0.0437015186,"0.7000000000000001":0.0541653125,"0.75":0.0645647261,"0.8":0.066830029,"0.8500000000000001":0.0870890486,"0.9":0.111049417,"0.9500000000000001":0.1952701237,"1.0":0.739677633},"(\'price\', \'cu2007\')":{"0.0":0.0,"0.05":0.0,"0.1":0.0,"0.15000000000000002":0.0,"0.2":0.0107307651,"0.25":0.0108342362,"0.30000000000000004":0.0109349371,"0.35000000000000003":0.0214661372,"0.4":0.0216731686,"0.45":0.0220361393,"0.5":0.0322026621,"0.55":0.0326299761,"0.6000000000000001":0.0427853246,"0.65":0.0435019032,"0.7000000000000001":0.0536768653,"0.75":0.0554877372,"0.8":0.0665705093,"0.8500000000000001":0.0859660434,"0.9":0.1104362231,"0.9500000000000001":0.1879699248,"1.0":0.782196761},"(\'price\', \'cu2008\')":{"0.0":0.0,"0.05":0.0,"0.1":0.0,"0.15000000000000002":0.0106963312,"0.2":0.0108084738,"0.25":0.0109926349,"0.30000000000000004":0.0214178625,"0.35000000000000003":0.0216379963,"0.4":0.0221018897,"0.45":0.0321750322,"0.5":0.0326299761,"0.55":0.0428311382,"0.6000000000000001":0.0434877147,"0.65":0.0535274596,"0.7000000000000001":0.0545077946,"0.75":0.0649561546,"0.8":0.0759960916,"0.8500000000000001":0.0961846746,"0.9":0.1218431546,"0.9500000000000001":0.1988730527,"1.0":0.94578247},"(\'price\', \'cu2009\')":{"0.0":0.0,"0.05":0.0,"0.1":0.0,"0.15000000000000002":0.0,"0.2":0.010686044,"0.25":0.0107642626,"0.30000000000000004":0.0108283703,"0.35000000000000003":0.0212765957,"0.4":0.0215053763,"0.45":0.0216943269,"0.5":0.0320307495,"0.55":0.032449973,"0.6000000000000001":0.042593973,"0.65":0.0433228636,"0.7000000000000001":0.053561864,"0.75":0.0641162642,"0.8":0.074906367,"0.8500000000000001":0.0883782589,"0.9":0.1300672014,"0.9500000000000001":0.2331261101,"1.0":0.778679535},"(\'price\', \'cu2010\')":{"0.0":0.0,"0.05":0.0,"0.1":0.0,"0.15000000000000002":0.0106598444,"0.2":0.0107712193,"0.25":0.0110217128,"0.30000000000000004":0.0215354797,"0.35000000000000003":0.0319216855,"0.4":0.0323939099,"0.45":0.0427441761,"0.5":0.0532141337,"0.55":0.054206418,"0.6000000000000001":0.0646342777,"0.65":0.0747224594,"0.7000000000000001":0.0853697578,"0.75":0.0967014075,"0.8":0.1099989,"0.8500000000000001":0.1320422535,"0.9":0.1623025319,"0.9500000000000001":0.2554278416,"1.0":2.5132705016},"(\'price\', \'cu2011\')":{"0.0":0.0,"0.05":0.0,"0.1":0.0,"0.15000000000000002":0.0106462259,"0.2":0.0107921433,"0.25":0.0212811236,"0.30000000000000004":0.0216614318,"0.35000000000000003":0.0323415265,"0.4":0.0431872166,"0.45":0.0539548937,"0.5":0.0650406504,"0.55":0.0758972135,"0.6000000000000001":0.0873362445,"0.65":0.0985761227,"0.7000000000000001":0.1099021871,"0.75":0.1275645796,"0.8":0.1402827236,"0.8500000000000001":0.1620045361,"0.9":0.2016129032,"0.9500000000000001":0.3650442478,"1.0":2.5024587477},"(\'price\', \'cu2012\')":{"0.0":0.0,"0.05":0.0,"0.1":0.0,"0.15000000000000002":0.0106269926,"0.2":0.0107296137,"0.25":0.0109625082,"0.30000000000000004":0.0214546235,"0.35000000000000003":0.0318775901,"0.4":0.0324184137,"0.45":0.0429000429,"0.5":0.0532028091,"0.55":0.0638365784,"0.6000000000000001":0.0744522442,"0.65":0.085515767,"0.7000000000000001":0.0965043963,"0.75":0.1092060719,"0.8":0.1280956447,"0.8500000000000001":0.1486357363,"0.9":0.1768542058,"0.9500000000000001":0.2403846154,"1.0":1.3820441397},"(\'price\', \'cu2101\')":{"0.0":0.0,"0.05":0.0,"0.1":0.0,"0.15000000000000002":0.0106168383,"0.2":0.0107933081,"0.25":0.0214247456,"0.30000000000000004":0.031870817,"0.35000000000000003":0.04264847,"0.4":0.0531067446,"0.45":0.0638841567,"0.5":0.0750509274,"0.55":0.0860770389,"0.6000000000000001":0.0967950097,"0.65":0.1076310408,"0.7000000000000001":0.1183686646,"0.75":0.1379749522,"0.8":0.1543380002,"0.8500000000000001":0.1828153565,"0.9":0.2363304329,"0.9500000000000001":0.7269617276,"1.0":2.8963414634},"(\'price\', \'cu2102\')":{"0.0":0.0,"0.05":0.0,"0.1":0.0,"0.15000000000000002":0.0,"0.2":0.0106871861,"0.25":0.0212134069,"0.30000000000000004":0.0322130355,"0.35000000000000003":0.0537345513,"0.4":0.0873553178,"0.45":0.1270244522,"0.5":0.1591005515,"0.55":0.1960143744,"0.6000000000000001":0.2392604676,"0.65":0.2866546342,"0.7000000000000001":0.32873807,"0.75":0.3646894776,"0.8":0.4151586119,"0.8500000000000001":0.4710416444,"0.9":0.5397819281,"0.9500000000000001":0.7334963325,"1.0":3.0713447798}}'
plot_data = df_max_chng_3m.quantile(np.arange(0,1.05, 0.05)) *100
colors = ['#a6cee3','#1f78b4','#b2df8a','#33a02c','#fb9a99','#e31a1c','#fdbf6f',
'#ff7f00','#cab2d6','#6a3d9a','#ffff99','#b15928']
plot_data.plot(kind = 'bar', color = colors)
plt.title('Quantiles of Maximum Percent Change of Price over a 3 Minutes window', fontsize = 18)
plt.ylabel('Maximum Percent Change of Price \n Over a 3 minutes window (%)')