Моя логика неверна? Я не понимаю происходящего поведения.
Это код, который я написал:
Код: Выделить всё
import numpy as np
import matplotlib.pyplot as plt
new_ticks = [2.0, 2.75]
a = np.array([1,2,3,4,5])
b = np.array([1,2,3,4,5])
plt.plot(a,b)
for new_tick in new_ticks: #test both if-conditions in loop
xticks = list(plt.xticks()[0]) #get x-axis ticks
if new_tick not in xticks: #if d is not in the x-axis ticks
plt.xticks(xticks + [new_tick]) #add d to x-axis ticks
xticks = list(plt.xticks()[0]) #get x-axis ticks again since tick d may have been added
index = xticks.index(new_tick) #find index where d is
plt.gca().get_xticklines()[index].set_markeredgecolor('red') #make the tick color red where d is
plt.show()

Для второго графика я получаю красную галочку, но ось X изменена:

Подробнее здесь: https://stackoverflow.com/questions/798 ... matplotlib
Мобильная версия