Вы можете использовать:
plt.xscale('log')
, чтобы изменить масштаб на логарифмический масштаб set_major_formatter(ScalarFormatter())
, чтобы вернуть нормальное форматирование ( заменив LogFormatter
) set_minor_locator(NullLocator())
, чтобы удалить второстепенные отметки (которые также были установлены шкалой журнала) set_major_locator(FixedLocator([...]
или plt.xticks([...])
, чтобы установить желаемые отметки на ось x
import matplotlib.pyplot as plt
from matplotlib.ticker import ScalarFormatter, NullLocator, FixedLocator
import numpy as np
x = np.arange(520)
y = np.random.uniform(-1, 1, 520).cumsum()
plt.plot(x, y)
plt.xscale('log')
# plt.xticks([...])
plt.gca().xaxis.set_major_locator(FixedLocator([2**i for i in range(0, 7)] + [130, 260, 510]))
plt.gca().xaxis.set_major_formatter(ScalarFormatter())
plt.gca().xaxis.set_minor_locator(NullLocator())
plt.show()
пример сюжета