pyplot:如何以人类可读的方式显式地对轴进行编号

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了pyplot:如何以人类可读的方式显式地对轴进行编号相关的知识,希望对你有一定的参考价值。

Pyplot有一个奇怪的特性,对于大数字,轴由非基数十个数字缩放,几乎不可能读取数值:

x = [49856280.352, 49860580.25, 49861011.77, 49861103.034, 49861191.295, 49862295.297, 49862311.928, 49862755.161, 49863005.142, 49863331.328, 49863795.672, 49863892.911, 49864078.203, 49864455.172, 49864628.486, 49865539.345, 49865562.414, 49865652.025, 49865860.79, 49866049.199, 49866559.841, 49866709.259, 49866976.163, 49867118.158, 49867184.515, 49867228.03, 49867703.98, 49868191.475, 49868264.993, 49868402.682, 49868547.472, 49868849.941, 49869167.486, 49869233.011, 49869388.16, 49869462.118, 49869947.616, 49869976.177, 49870146.971, 49870441.068, 49870858.267, 49870898.339, 49870966.598, 49871065.408, 49871113.361, 49871268.792, 49871332.292, 49872008.637, 49872014.321, 49872128.757, 49872276.278, 49872296.18, 49872322.098, 49872366.707, 49872370.336, 49872537.099, 49872909.555, 49872917.363, 49873131.438, 49873230.402, 49873252.129, 49873289.302, 49873382.584, 49873429.968, 49873440.124, 49873444.505, 49873507.617, 49873835.836, 49873905.902, 49873965.72, 49874080.127, 49874101.966, 49874166.944, 49874359.819, 49874388.385, 49874412.152, 49874421.629, 49874584.264, 49874755.328, 49874798.936, 49874833.007, 49875145.279, 49875310.799, 49875391.973, 49875484.389, 49875615.09, 49875616.889, 49875773.568, 49875776.696, 49875892.137, 49875953.749, 49875954.395, 49876161.776, 49876220.899, 49876321.362, 49876380.343, 49876496.107, 49876595.953, 49876644.428, 49876655.041, 49876714.369, 49876770.925, 49876788.46, 49876932.063, 49876952.641, 49877075.874, 49877105.142, 49877220.934, 49877288.062, 49877294.256, 49877308.79, 49877551.764, 49877586.774, 49877620.658, 49877666.194, 49877842.635, 49878091.505, 49878171.278, 49878181.791, 49878229.777, 49878244.476, 49878483.22, 49878541.483, 49878602.181, 49878612.309, 49878615.488, 49878677.558, 49878683.807, 49878703.616, 49878785.269, 49878793.774, 49878922.532, 49878933.228, 49878981.748, 49879041.296, 49879060.17, 49879263.424, 49879355.213, 49879449.193, 49879455.009, 49879471.561, 49879508.752, 49879538.815, 49879597.852, 49879683.744, 49879727.257, 49879751.962, 49879895.858, 49879960.524, 49880178.136, 49880196.753, 49880217.788, 49880336.479, 49880370.356, 49880396.479, 49880422.808, 49880539.652, 49880559.579, 49880624.786, 49880704.456, 49880739.891, 49880836.13, 49880886.385, 49880938.998, 49881169.02, 49881288.366, 49881305.161, 49881426.038, 49881427.956, 49881463.834, 49881617.346, 49881730.679, 49881881.14, 49881894.675, 49881979.949, 49882096.47, 49882112.031, 49882131.716, 49882159.639, 49882190.252, 49882483.949, 49882538.07, 49882583.816, 49882597.938, 49882602.861, 49882611.359, 49882648.24, 49882684.267, 49882706.434, 49882835.084, 49883043.946, 49883084.906, 49883109.752, 49883228.104, 49883288.07, 49883382.503, 49883401.475, 49883491.927, 49883574.922, 49883654.813, 49883702.522, 49883801.5, 49883814.683, 49883826.244, 49883846.713, 49883855.077, 49883978.159, 49884046.234, 49884064.489, 49884112.738, 49884138.818, 49884220.732, 49884251.195, 49884255.97, 49884361.999, 49884397.955, 49884416.274, 49884498.095, 49884516.764, 49884548.794, 49884580.933, 49884597.752, 49884624.897, 49884634.323, 49884670.05, 49884676.813, 49884733.419, 49884751.203, 49884834.288, 49884888.879, 49884902.225, 49885004.171, 49885153.972, 49885157.866, 49885173.615, 49885174.386, 49885219.196, 49885273.781, 49885347.517, 49885364.666, 49885380.826, 49885427.356, 49885509.155, 49885541.137, 49885578.287, 49885595.473, 49885612.014, 49885710.601, 49885740.394, 49885741.348, 49885841.454, 49885952.568, 49885988.633, 49886053.94, 49886058.886, 49886076.628, 49886095.714, 49886147.686, 49886164.4, 49886179.103, 49886201.971, 49886279.139, 49886312.282, 49886312.8, 49886324.598, 49886408.542, 49886481.161, 49886548.747, 49886641.616, 49886642.093, 49886668.221, 49886675.982, 49886725.046, 49886741.706, 49886821.745, 49886833.46, 49886840.54, 49886850.264, 49886873.972, 49887005.587, 49887042.942, 49887073.685, 49887076.296, 49887091.248, 49887105.67, 49887148.602, 49887159.267, 49887271.173, 49887285.866, 49887303.534, 49887369.19, 49887382.49, 49887454.943, 49887479.589, 49887498.203, 49887616.744, 49887721.935, 49887747.864, 49887786.036, 49887803.228, 49887858.683, 49887943.768, 49888058.328, 49888058.963, 49888148.314, 49888200.419, 49888346.257, 49888362.013, 49888366.362, 49888406.004, 49888450.807, 49888497.044, 49888614.062, 49888622.199, 49888628.315, 49888717.575, 49888731.575, 49888736.902, 49888765.916, 49888803.98, 49888875.799, 49888892.348, 49888934.101, 49888967.728, 49888974.393, 49888981.908, 49889075.143, 49889221.983, 49889255.367, 49889277.661, 49889298.851, 49889319.147, 49889320.207, 49889407.915, 49889413.481, 49889429.941, 49889469.243, 49889487.959, 49889532.295, 49889539.477, 49889552.03, 49889572.229, 49889585.375, 49889602.118, 49889668.329, 49889683.014, 49889697.206, 49889772.868, 49889806.44, 49889881.148, 49889916.157, 49889961.726, 49889989.911, 49889997.299, 49890021.069, 49890092.985, 49890123.557, 49890137.558, 49890249.033, 49890337.341, 49890363.69, 49890412.835, 49890438.527, 49890455.844, 49890457.272, 49890540.923, 49890552.792, 49890571.653, 49890656.799, 49890657.446, 49890771.402, 49890893.014, 49890940.859, 49891117.607, 49891188.608, 49891197.473, 49891204.319, 49891260.746, 49891286.509, 49891329.619, 49891369.244, 49891373.448, 49891400.609, 49891594.308, 49891664.373, 49891769.784, 49891812.789, 49891878.95, 49891889.874, 49891924.49, 49891962.647, 49891972.677, 49892086.585, 49892096.15, 49892131.411, 49892145.241, 49892147.07, 49892186.586, 49892221.814, 49892257.429, 49892295.906, 49892366.592, 49892414.483, 49892486.488, 49892505.361, 49892571.789, 49892614.344, 49892775.098, 49892807.812, 49892832.242, 49892837.597, 49892858.141, 49892894.853, 49892896.347, 49893017.939, 49893029.177, 49893118.449, 49893168.059, 49893232.781, 49893235.78, 49893287.331, 49893326.778, 49893406.653, 49893471.93, 49893495.472, 49893510.31, 49893593.136, 49893668.36, 49893690.138, 49893717.478, 49893841.341, 49893849.407, 49893918.451, 49893929.304, 49893965.073, 49893995.907, 49894105.083, 49894113.528, 49894207.766, 49894220.283, 49894229.309, 49894287.256, 49894296.334, 49894321.153, 49894394.072, 49894410.075, 49894426.245, 49894429.549, 49894486.508, 49894569.593, 49894596.175, 49894646.893, 49894684.32, 49894706.127, 49894730.259, 49894814.007, 49894846.182, 49894921.957, 49895075.836, 49895134.196, 49895411.552, 49895467.919, 49895581.219, 49895643.126, 49895681.785, 49895715.833, 49895717.103, 49895732.304, 49895747.613, 49895775.574, 49895797.26, 49895801.342, 49895905.897, 49895914.703, 49895933.794, 49895949.521, 49895999.669, 49896017.596, 49896189.338, 49896213.562, 49896231.62, 49896310.695, 49896462.188, 49896483.7, 49896508.985, 49896602.682, 49896631.951, 49896719.268, 49896806.399, 49896806.913, 49896872.332, 49897018.727, 49897124.196, 49897134.793, 49897213.913, 49897270.838, 49897284.028, 49897315.792, 49897330.168]
plt.hist(x)
plt.show()

enter image description here

在我的例子中,轴应缩放1e7或1e8,或显示为rgular数字 - 而不是4.986e7。为什么有人想要这个设置?如何使x轴编号具有人类可读性?

答案

How to prevent numbers being changed to exponential form in Python matplotlib figure

ax = plt.gca()
ax.get_xaxis().get_major_formatter().set_useOffset(False)
ax.get_xaxis().get_major_formatter().set_scientific(False)
plt.draw()

以上是关于pyplot:如何以人类可读的方式显式地对轴进行编号的主要内容,如果未能解决你的问题,请参考以下文章

如何以 json 格式(双引号)漂亮地打印(人类可读的打印)Python dict? [复制]

以人类可读的形式在 QSettings 中保存自定义 QMap 模板实例化

格式化日期对象以显示人类可读的日期

以人类可读的格式显示容器弃用日志?

人类可读的 JSON:又名在 json 转储中添加空格和中断

如何将字符串时间戳更改为人类可读的日期格式? [复制]