Matplotlib logarithmic x-axis and padding
<p>I am struggling with matplotlib and padding on the x-axis together with a logarithmic scale (see the first picture).
Without a logarithmic scale, the padding applies nicely (see the second one).
Any suggestations how to get a padding between plot lines and the axis line in the bottom left corner so that one can see the points on the line?</p>

<p>Thanks.</p>

<p>The code:</p>

<pre><code>import matplotlib.pyplot as plt
import numpy as np
from matplotlib.pyplot import *
from matplotlib.ticker import ScalarFormatter

style.use('fivethirtyeight')

fig, ax = plt.subplots()

T = np.array([2**x for x in range(0,7+1)])
opt1 = np.array([x for x in range(0,7+1)])
opt2 = np.array([x*2 for x in range(0,7+1)])
opt3 = np.array([x*4 for x in range(0,7+1)])

ax.grid(True) 
xlabel("#nodes")
ylabel("time(s)")
legend(loc="best") 
title(r"Node start times") 

plt.xticks([2**x for x in range(0,7+1)])

plt.plot(T,opt1,"o-", label="opt1")
plt.plot(T,opt2, "s-", label="opt2")
plt.plot(T,opt3, "d-", label="opt2")
plt.legend(loc="upper left")
# This should be called after all axes have been added
plt.tight_layout()
plt.margins(0.05, 0.05)
# 1, 2, 4, ...
ax.set_xscale('log', basex=2)
ax.xaxis.set_major_formatter(matplotlib.ticker.FormatStrFormatter("%d"))
plt.show()
#savefig("plot_1.pdf")
</code></pre>

<p><a href="https://i.stack.imgur.com/UoHFO.png" rel="nofollow"><img src="https://i.stack.imgur.com/UoHFO.png" alt="Plot Log Scale"></a>
<a href="https://i.stack.imgur.com/69RP7.png" rel="nofollow"><img src="https://i.stack.imgur.com/69RP7.png" alt="Plot Normal"></a></p>

<p>This does not address your padding issue, but you could use <code>clip_on=False</code> to prevent the points from being cut off. It seems you also need to make sure they're above the axes using <code>zorder</code></p>

<pre><code>plt.plot(T,opt1,"o-", label="opt1", clip_on=False, zorder=10)
plt.plot(T,opt2, "s-", label="opt2", clip_on=False, zorder=10)
plt.plot(T,opt3, "d-", label="opt2", clip_on=False, zorder=10)
</code></pre>

python matplotlib padding