Python Forum
New to Python & Matplotlib - can I change the plot grid origin to lower left corner? - Printable Version

+- Python Forum (https://python-forum.io)
+-- Forum: Python Coding (https://python-forum.io/forum-7.html)
+--- Forum: Data Science (https://python-forum.io/forum-44.html)
+--- Thread: New to Python & Matplotlib - can I change the plot grid origin to lower left corner? (/thread-29079.html)



New to Python & Matplotlib - can I change the plot grid origin to lower left corner? - FortyTwo - Aug-17-2020

I'm completely new to Python and can't figure out what search terms to use to find the answer. I'm plotting very small images from a CCD and would like the grid/axes (0, 0) point to be in the lower left corner - not the middle of the rows/columns; that aligns the grid to the middle of the pixels. Here is the code I'm using for a 5 pixel x 5 pixel image showing a very "zoomed in" view of the CCD:

import matplotlib.pyplot as plt
import numpy as np

image = [[175.94289, 177.74895, 158.87912, 145.34993, 148.05937],
        [177.55653, 165.20393, 160.09775, 161.71048, 149.43646],
        [162.94765, 160.01396, 204.08203, 289.2722,  221.55945],
        [147.64162, 153.57835, 331.3954, 383.78668, 233.15973],
        [146.21872, 154.15912, 230.50053, 234.13762, 186.50993]]

npimage = np.array(image)

fig = plt.figure(figsize=(5, 5))
axes = fig.add_axes
plt.imshow(npimage, origin='lower', cmap='YlGnBu_r',
           vmax=np.percentile(npimage, 98), vmin=np.percentile(npimage, 5))
plt.xlabel('Image Column', fontsize=14)
plt.ylabel('Image Row', fontsize=14)
plt.grid(axis='both', color='white', ls='solid')

plt.show()



RE: New to Python & Matplotlib - can I change the plot grid origin to lower left corner? - matador - Aug-22-2020

Hello, I don't understand english very well but you should add this line in your code

plt.axis([0, 4, 0, 4])
Tell me if this is what you were searching for.