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')
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.
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.
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With