You could do this using ticks.
Let me present this approach with the following easy plot:
from matplotlib import pyplot as plt
ax = plt.axes()
ax.set_xlim(0, 3)
ax.set_ylim(0, 3)
for i in range(3):
for j in range(3):
ax.fill_between((i, i+1), j, j+1)
ax.fill_between((i, i+1), j, j+1)
ax.fill_between((i, i+1), j, j+1)
plt.show()

I will not focus on the colors neither on the tick style, but know that you can change these very easily.
You can create an Axes
object that will share ax
's Y axis, with ax.twiny()
. Then, you can add X ticks on this new Axes
, which will appear on top of the plot:
from matplotlib import pyplot as plt
ax = plt.axes()
ax.set_xlim(0, 3)
ax.set_ylim(0, 3)
for i in range(3):
for j in range(3):
ax.fill_between((i, i+1), j, j+1)
ax.fill_between((i, i+1), j, j+1)
ax.fill_between((i, i+1), j, j+1)
ax2 = ax.twiny()
ax2.set_xlim(ax.get_xlim())
ax2.set_xticks([0.5, 1.5, 2.5])
ax2.set_xticklabels([13, 0, 0])
plt.show()

In order to display ticks for the X axis, you have to create an Axes
object that shares ax
's Y axis, with ax.twiny()
. This might seem counter-intuitive, but if you used ax.twinx()
instead, then modifying ax2
's X ticks would modify ax
's as well, because they're actually the same.
Then, you want to set the X window of ax2
, so that it has three squares.
After that, you can set the ticks: one in every square, at the horizontal center, so at [0.5, 1.5, 2.5]
.
Finally, you can set the tick labels to display the desired value.
Then, you just do the same with the Y ticks:
from matplotlib import pyplot as plt
ax = plt.axes()
ax.set_xlim(0, 3)
ax.set_ylim(0, 3)
for i in range(3):
for j in range(3):
ax.fill_between((i, i+1), j, j+1)
ax.fill_between((i, i+1), j, j+1)
ax.fill_between((i, i+1), j, j+1)
ax2 = ax.twiny()
ax2.set_xlim(ax.get_xlim())
ax2.set_xticks([0.5, 1.5, 2.5])
ax2.set_xticklabels([13, 0, 0])
ax3 = ax.twinx()
ax3.set_ylim(ax.get_ylim())
ax3.set_yticks([0.5, 1.5, 2.5])
ax3.set_yticklabels([0, 6, 9])
plt.show()
