Reputation: 3204
How would you add a margin between the axis lines and the actual origin? In 3D scatter, like this one, the origin of x = 6
and y = -10
are not on the same point. How to do the same thing but in a 2D scatter (something similar to the graphic of p. 122 (132 of pdf) in this matplotlib doc, where the origin x = 0
and y = 0
are not located at the same place).
Upvotes: 2
Views: 1663
Reputation: 12234
A margin can be easily added to any plot by supplying the plt.set_xmargin(m)
with a float between 0 and 1 indicating the relative size of the margin:
import matplotlib.pyplot as plt
import numpy as np
fig =plt.figure()
ax = plt.subplot(111)
x = np.linspace(0, 10, 100)
y = np.cos(x)
ax.set_xmargin(0.2)
ax.set_ymargin(0.2)
ax.plot(x, y)
Note in practise this needs to be called before ax.plot(..
as this is when the autoscaling is done. For more information see here
Upvotes: 4