1

The y axis of my matplotlib bar chart is between 0 and 1. However, all values for in the chart are between 0.8 and 1 so I would like to start the y axis at 0.7. I haven't been able to find the pandas method of doing this so any help would be appreciated.

Thanks in advance

toothsie
  • 245
  • 3
  • 10

1 Answers1

2

New Answer

@ChrisA has provided the best answer in the comments: If using DataFrame.plot() method, add argument ylim=(0.7, 1)

Old Answer

If you've used the usual import matplotlib.pyplot as plt, a quick fix could be to add the following lines under your pandas plot command:

# gca = "get current axis"
ax = plt.gca()

# ax.get_ylim() returns a tuple of (lower ylim, upper ylim)
ax.set_ylim(0.7, ax.get_ylim()[1])

If you're using the object-oriented matplotlib API that typically starts with something like fig, ax = plt.subplots() (reference: The Lifecycle of a Plot), then you won't need to run ax = plt.gca().

Peter Leimbigler
  • 10,775
  • 1
  • 23
  • 37