dantebarba dantebarba - 8 days ago 7
Python Question

How to set ticks on Fixed Position , matplotlib

Can anyone help me set the ticks on a fixed position using matplotlib? I've tried using FixedPosition as this tutorial describes:

ax = pl.gca()
ax.xaxis.set_major_locator(eval(locator))


http://scipy-lectures.github.io/intro/matplotlib/matplotlib.html#figures-subplots-axes-and-ticks

But when I try to run, it tells me that set_major_locator method does not exist.

A simple example would be very useful.

Thanks.

Answer

Just use ax.set_xticks(positions) or ax.set_yticks(positions).

For example:

import matplotlib.pyplot as plt

fig, ax = plt.subplots()
ax.set_xticks([0.15, 0.68, 0.97])
ax.set_yticks([0.2, 0.55, 0.76])
plt.show()

enter image description here

Comments