Plot some numbers in x axis
<p>My question is related to the figure format generated using the matplotlib library.</p>

<p>So, in the x axis, I have the integers from 1 to 100, but in my code I plot just the data related to some numbers (e.g 1,5,77,86,97).</p>

<p>At the end, my code shows me a figure with x axis from 1 to 100.</p>

<p>How can I show just the needed numbers (1,5,77,86,97)?</p>

<p>My code is shown below:</p>

<pre><code>def Plot(self,x,y, steps, nb,bool):  
    if(bool == False):

        labelfont = {
                'family' : 'sans-serif',  # (cursive, fantasy, monospace, serif)
                'color'  : 'black',       # html hex or colour name
                'weight' : 'normal',      # (normal, bold, bolder, lighter)
                'size'   : 20,            # default value:12
                }

        titlefont = {
                'family' : 'serif',
                'color'  : 'black',
                'weight' : 'bold',
                'size'   : 20,
                }

        x = np.array(x)
        y = np.array(y)
        pylab.plot(x, y,
                 'darkmagenta',                       # colour
                 linestyle='',                      # line style
                 linewidth=10,                       # line width
                 marker = '+',
                 mew=6, ms=12)

        axes = plt.gca()
        axes.grid(True)
        axes.set_xlim([1, x_max)            # x-axis bounds
        axes.set_ylim([1, nb])              # y-axis bounds

        pylab.title('Title' , fontdict=titlefont)
        pylab.xlabel('x', fontdict=labelfont)
        pylab.ylabel('y', fontdict=labelfont)

        pylab.subplots_adjust(left=0.15)        # prevents overlapping of the y label
    else:
        test_steps.insert(0,"")
        pylab.yticks(nb,  steps,rotation=0, size=10)
        pylab.margins(0.2)
        pylab.xticks(np.arange(0, x_max, 1.0),rotation=90, size=10)
        # Tweak spacing to prevent clipping of tick-labels
        pylab.subplots_adjust(bottom=0.15)
        F = pylab.gcf()
        DefaultSize = F.get_size_inches()
        if x_max &lt; 100 and len(steps) &lt; 100:
            Xx = 2.5
            Yy = 2.5
        elif x_max &lt; 200 and len(steps) &lt; 200:
            Xx = 5
            Yy = 5
        elif ix_max &lt; 300 and len(steps) &lt; 300:
            Xx = 8
            Yy = 8
        elif x_max &lt; 400 and steps &lt; 400:
            Xx = 10
            Yy = 10
        elif x_max &lt; 500 and steps &lt; 500:
            Xx = 12
            Yy = 12
        else:
            Xx = 15
            Yy = 15
        F.set_size_inches((DefaultSize[0]*Xx , DefaultSize[1]*Yy))
        F.savefig('Out.png', bbox_inches='tight')
        pylab.close(F)
</code></pre>