“Setting up tick label, The disappearance of first array list, jumping up to the second array list”, so basically why the first array not setted up?

Please see the result below, as you can see in the image when i set the label it suddenly jump to second list (x_tick[1] and y_tick[1]) why? what happen to first list (x_tick[0] and y_tick[0]).

When i use image to plot this happen but without image it show up.

Note: for image in matplotlib. y label, set from top to bottom and x label, set from left to right

import pandas as pd
import numpy as np
import matplotlib.pyplot as plt
from PIL import Image, ImageDraw



point=(1.28358, 103.86921, 1.11504, 104.16138) #BATAM3
im = Image.open('BATAM3.png', 'r')
x_tick = list(map(lambda x: round(x, 7), np.linspace(point[1], point[3], endpoint=True, num=9)))
y_tick = list(map(lambda x: round(x, 7), np.linspace(point[2], point[0], endpoint=True, num=6)))
y_tick = sorted(y_tick, reverse=True)


print(x_tick)
print(y_tick)
#print(x_tick[0])

fig, ax = plt.subplots(figsize=(15, 15))
ax.imshow(im)
ax.set_xlabel('Longitude')
ax.set_ylabel('Latitude')
ax.set_xticklabels(x_tick)
ax.set_yticklabels(y_tick)
ax.grid()

This yields:

[103.86921, 103.9057312, 103.9422525, 103.9787737, 104.015295, 104.0518162, 104.0883375, 104.1248587, 104.16138]
[1.28358, 1.249872, 1.216164, 1.182456, 1.148748, 1.11504]

here the result for the image imshow(im) :

https://files.fm/thumb_show.php?i=c6u8b5bhg

to make my question easy to understand :

https://files.fm/thumb_show.php?i=7vucbyuhg

Answer

As the documentation says, you need to set the ticks locations using set_xticks first before setting the labels.

https://matplotlib.org/stable/api/_as_gen/matplotlib.axes.Axes.set_xticklabels.html

w, l = im.size
x_pos = list(map(lambda x: round(x), np.linspace(0, w, endpoint=True, num=9)))

fig, ax = plt.subplots(figsize=(15, 15))
ax.imshow(im)
ax.set_xlabel('Longitude')
ax.set_ylabel('Latitude')
ax.set_xticks(x_pos) #set the positions
ax.set_xticklabels(x_tick)
ax.set_yticklabels(y_tick)
ax.grid()