Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I remove the y-axis from a Pylab-generated picture?

import pylab  # matplotlib

x_list = [1,1,1,1,5,4]
y_list = [1,2,3,4,5,4]

pylab.plot(x_list, y_list, 'bo')

pylab.show()

What I want to do is remove the y-axis from the diagram, only keeping the x-axis. And adding more margin to the diagram, we can see that a lot of dots are on the edge of the canvas and don't look good.

like image 660
user469652 Avatar asked Oct 07 '10 22:10

user469652


People also ask

How do I get rid of Y-axis in Matplotlib?

If we just want to turn either the X-axis or Y-axis off, we can use plt. xticks( ) or plt. yticks( ) method respectively.

How do you get rid of an axis?

Click anywhere in the chart for which you want to display or hide axes. This displays the Chart Tools, adding the Design, Layout, and Format tabs. On the Layout tab, in the Axes group, click Axes. Click the type of axis that you want to display or hide, and then click the options that you want.

How do I get rid of the axis in Python?

ax. remove() is all we need. It simply removes the axis from the figure.


1 Answers

ax = pylab.gca()
ax.yaxis.set_visible(False)
pylab.show()
like image 162
Jim Brissom Avatar answered Sep 22 '22 07:09

Jim Brissom