The Unfun Cat
The Unfun Cat

Reputation: 31918

xticks ends placement of numbers on x-axis prematurely, i.e. the ticks do not reach the right end

I have a simple script that graphs the TPR/SP tradeoff.

It produces a pdf like (note the placement of the x-axis numbers): enter image description here

The relevant code is likely:

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

The whole code is:

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')

Upvotes: 1

Views: 199

Answers (3)

Saullo G. P. Castro
Saullo G. P. Castro

Reputation: 58895

You can call autoscale() after xticks(), which will set the new axes' limits automatically.

enter image description here

Upvotes: 2

Pablo
Pablo

Reputation: 2481

For some reason that I can not see, the autoscale doesn't work with your plot... In this case, you must to force the x-scale of the plot:

You can try doing:

nticks = len(SP_list)
ticks = arange(nticks)
xticks(ticks, 0.1*ticks, size='small')
xlim(ticks.min(), ticks.max())
show()

Upvotes: 1

tacaswell
tacaswell

Reputation: 87376

It is doing exactly what you told it to. The problem is a poor interaction of the default tick locator and your use of xticks. By default the locator tries to set a range to give you 'nice' tick locations. If you remove the xticks line, you will see that it gives you a range of [0, 25]. When you use xticks it puts the given string at the given location, but does not change the limits. You just need to set the limits by adding

xlim([0, len(SP_list) - 1])

Upvotes: 1

Related Questions