python - xticks 过早结束 x 轴上数字的放置,即刻度没有到达右端

标签 python python-2.7 matplotlib

我有一个简单的脚本来绘制 TPR/SP 权衡图。

它生成的 pdf 格式如下(注意 x 轴数字的位置):enter image description here

相关代码大概是:

xticks(range(len(SP_list)), [i/10.0 for i in range(len(SP_list))], size='small')

整个代码是:

SN_list = [0.89451476793248941, 0.83544303797468356, 0.77215189873417722, 0.70042194092827004, 0.63291139240506333, 0.57805907172995785, 0.5527426160337553, 0.5527426160337553, 0.53586497890295359, 0.52742616033755274, 0.50632911392405067, 0.48101265822784811, 0.45569620253164556, 0.43459915611814348, 0.40084388185654007, 0.3628691983122363, 0.31223628691983124, 0.25738396624472576, 0.20253164556962025, 0.12658227848101267, 0.054852320675105488, 0.012658227848101266]
SP_list = [0.24256292906178489, 0.24780976220275344, 0.25523012552301255, 0.25382262996941896, 0.25684931506849318, 0.36533333333333334, 0.4548611111111111, 0.51778656126482214, 0.54978354978354982, 0.59241706161137442, 0.63492063492063489, 0.80851063829787229, 0.81203007518796988, 0.85123966942148765, 0.88785046728971961, 0.91489361702127658, 0.9135802469135802, 0.9242424242424242, 0.94117647058823528, 0.967741935483871, 1.0, 1.0]

figure()

xlabel('Score cutoff point')

ylabel('Percent')

plot(SP_list)

plot(SN_list)

legend(('True Positive Rate', 'Specificity'), 'upper left', prop={"size":9}, shadow=False, fancybox=False)

grid(False)

xticks(range(len(SP_list)), [i/10.0 for i in range(len(SP_list))], size='small')

savefig('SP_SN.png')

最佳答案

您可以在 xticks() 之后调用 autoscale(),这将自动设置新轴的限制。

enter image description here

关于python - xticks 过早结束 x 轴上数字的放置,即刻度没有到达右端,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17512826/

相关文章:

python - 在python中自定义字典迭代器

python - 使用 python_requires 要求 Python 2.7 或 3.2+

Python seaborn catplot - 如何将 y 轴刻度更改为百分比

python - 更改特定子图背景颜色(饼图之外)

python - 如何在Python中绘制重叠簇

python - Emacs:终止正在运行的 python 脚本

python:比较这些列表的快速简便方法?

Python 代码输出到文件并在文件名中添加时间戳

python - 在 Python 中对文件内容进行排序

python - 无法在 Python 中导入 urllib