Consider the simple plot import matplotlib.pyplot as plt x = [0.9, 1, 1.1, 1.2, 1.3] y = [0, 0.1, 0.3, 0.6, 1] plt.plot(x,y) plt.margins(x=0, y=0) plt.xlim(0,3) This generates a line plot. From here I would like to colour part of my x-axis such that from 0 to 0.9 is blue and from 0.9 to 3 is red. One solution I came up with is include two more line plots: plt.plot([0,0.9], [0,0], color = "b" ,linewidth=3.0) and plt.plot([0.9,3.0], [0,0], color = "r",linewidth=3.0). Giving the following picture: This looks okay, but I'm not entirely happy with it. To me it is clear that those lines are not on the axis, but rather slightly above the axis. Instead I would prefer to have the axis + ticks take on the respective colour. Continue reading...