How to show (0,0) on matplotlib graph at the bottom left corner?

When plotting data with matplotlib, the default axis limits might not show the origin (0,0) at the bottom left corner. You can control this by setting explicit axis limits using xlim() and ylim() methods.

Basic Example

Here's how to ensure (0,0) appears at the bottom left corner of your plot ?

import numpy as np
import matplotlib.pyplot as plt

# Sample data points
x = np.array([1, 2, 3, 4, 5])
y = np.array([2, 4, 1, 5, 3])

# Create the plot
plt.figure(figsize=(8, 6))
plt.plot(x, y, 'bo-', linewidth=2, markersize=6)

# Set axis limits to show (0,0) at bottom left
plt.xlim(0, max(x) + 0.5)
plt.ylim(0, max(y) + 0.5)

# Add labels and title
plt.xlabel('X Values')
plt.ylabel('Y Values')
plt.title('Plot with (0,0) at Bottom Left Corner')
plt.grid(True, alpha=0.3)

plt.show()

Understanding xlim() and ylim()

The key methods for controlling axis limits are ?

  • plt.xlim([min_value, max_value]) − Sets the x-axis range

  • plt.ylim([min_value, max_value]) − Sets the y-axis range

  • Setting minimum values to 0 ensures (0,0) is visible at the bottom left

Complete Example with Data Starting from Origin

Here's a more comprehensive example that includes the origin point ?

import numpy as np
import matplotlib.pyplot as plt

# Data that includes the origin point
x = np.array([0, 1, 2, 3, 4, 5])
y = np.array([0, 1, 4, 2, 5, 3])

plt.figure(figsize=(10, 6))

# Plot the data
plt.plot(x, y, 'ro-', linewidth=2, markersize=8, label='Data Points')

# Ensure (0,0) is at bottom left with some padding
plt.xlim(-0.2, max(x) + 0.5)
plt.ylim(-0.2, max(y) + 0.5)

# Highlight the origin point
plt.plot(0, 0, 'go', markersize=10, label='Origin (0,0)')

# Add grid and labels
plt.grid(True, alpha=0.3)
plt.xlabel('X Coordinate')
plt.ylabel('Y Coordinate') 
plt.title('Graph with Origin at Bottom Left Corner')
plt.legend()

# Add text annotation at origin
plt.annotate('(0,0)', xy=(0, 0), xytext=(0.3, 0.3), 
            arrowprops=dict(arrowstyle='->', color='red'))

plt.show()

Alternative Approach Using axis()

You can also use the axis() method to set all limits at once ?

import matplotlib.pyplot as plt
import numpy as np

x = np.array([2, 3, 4, 5])
y = np.array([3, 1, 4, 2])

plt.plot(x, y, 'bs-', markersize=8)

# Set axis limits: [xmin, xmax, ymin, ymax]
plt.axis([0, 6, 0, 5])

plt.title('Using axis() method')
plt.grid(True)
plt.show()

Key Points

  • Set xlim(0, max_x) to start x-axis from 0

  • Set ylim(0, max_y) to start y-axis from 0

  • Add small padding (like +0.5) to prevent data points from touching axis edges

  • Use axis([xmin, xmax, ymin, ymax]) as a shorthand for setting both limits

Conclusion

Use xlim(0, max_value) and ylim(0, max_value) to position (0,0) at the bottom left corner. This ensures your plot displays the full context of your data starting from the origin.

Updated on: 2026-03-26T14:55:43+05:30

14K+ Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements