python - How to edit x axis with pylab? -


here graph, seems on line x axis after 9. can me edit it? enter image description here

you can set x limits range, using either pyplot's xlim or object oriented interface ax.set_xlim. both take range arguments. if wanted set x-axis between 5 , 10, do:

plt.xlim((5,10))


example graph

given initial boilerplate set graph:

import matplotlib mpl import matplotlib.pyplot plt import numpy np fig = plt.figure() ax = fig.add_subplot(111) ax.set_ylim((0, 2100)) ax.bar(0, 2000, width=5) ax.bar(100, 500, width=5) ax.bar(40, 1500, width=5) 

you can use set_xlim change x limits:

ax.set_xlim((-50,150)) ax.set_xticks(np.arange(-50, 150, 20)) plt.show() 

example bar graph


generalizing + log scales

more generally, it's plt.xlim(left, right) left , right left , right boundaries want graph. units going same data feed in. if use log scale, values pass xlim applied normal scale (e.g., (0, 100) go (0, 10**2) on log graph)

you can use log scale same way (but it's bit finickier). log scale, need change xscale ax.set_xscale("log")


Comments

Popular posts from this blog

c# - DetailsView in ASP.Net - How to add another column on the side/add a control in each row? -

javascript - firefox memory leak -

Trying to import CSV file to a SQL Server database using asp.net and c# - can't find what I'm missing -