Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Changing x axis position from top to bottom on plt.Matshow

Tags:

python-3.x

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')

like image 317
Jacob Yoon Avatar asked Oct 17 '16 00:10

Jacob Yoon


People also ask

How do you flip the X-axis in Python?

Most common method is by using invert_xaxis() and invert_yaxis() for the axes objects. Other than that we can also use xlim() and ylim(), and axis() methods for the pyplot object. To invert X-axis and Y-axis, we can use invert_xaxis() and invert_yaxis() function.

How do I rotate X-axis labels in PLT?

Rotate X-Axis Tick Labels in Matplotlib There are two ways to go about it - change it on the Figure-level using plt. xticks() or change it on an Axes-level by using tick. set_rotation() individually, or even by using ax.


1 Answers

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

like image 143
unutbu Avatar answered Oct 11 '22 15:10

unutbu