8

I've searched high and low, but I can't seem to move the x axis from top to bottom using Matshow, I'm aware that imshow has the origin code to change the x axis position from top to bottom, but the question that I've got insists that I use Matshow, therefore is there a way to switch the a axis position?

t = [[(x+y+1)%2 for x in range(7)] for y in range (7)]
plt.matshow(t, interpolation="none")
plt.title('ArrayD')`
Henry Ecker
  • 34,399
  • 18
  • 41
  • 57
Jacob Yoon
  • 81
  • 1
  • 4

1 Answers1

10

Either call tick_bottom():

plt.matshow(t, interpolation="none")
plt.gca().xaxis.tick_bottom()

or use imshow instead of matshow:

plt.imshow(t, interpolation="none")

import numpy as np
import matplotlib.pyplot as plt

t = [[(x+y+1)%2 for x in range(7)] for y in range (7)]
plt.matshow(t, interpolation="none")
plt.title('ArrayD', y=1.01)
plt.gca().xaxis.tick_bottom()
plt.show()

yields

enter image description here

unutbu
  • 842,883
  • 184
  • 1,785
  • 1,677
  • Now there's a small margin between the title and the plot , is it possible to close the gap? – Jacob Yoon Oct 17 '16 at 00:18
  • You could use `plt.title('ArrayD', y=1.01)` to tighten the gap. See http://stackoverflow.com/a/23338363/190597. – unutbu Oct 17 '16 at 00:28