Formatting axes

Back in Chapter 1, Introduction to Data Analysis, we discussed how our axis limits can make for misleading plots if we aren't careful. With matplotlib, we can adjust the limits of each axis with plt.xlim() and plt.ylim(). We pass values for the minimum and maximum, separately; if we want to keep what was automatically generated, we can pass None. Let's plot Facebook stock's closing price and start the y-axis at zero:

>>> fb.open.plot(figsize=(10, 3), title='FB opening price 2018')>>> plt.ylim(0, None)>>> plt.ylabel('price ($)')

Notice that the y-axis now begins at zero:

We also have the option of passing this as a tuple to ...

Get Hands-On Data Analysis with Pandas now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.