[SciPy-User] [matplotlib] xgrid on values of x-variable?

Scott Sinclair scott.sinclair.za at gmail.com
Tue Jun 7 06:20:16 EDT 2011


On 7 June 2011 11:32, Klonuo Umom <klonuo at gmail.com> wrote:
> I have very simple XY graph, and I want to display X grid only, and only
> on values of X variable, which are lets say [10, 11, 12, 15, 20]

This is a question for the Matplotlib list
(https://lists.sourceforge.net/lists/listinfo/matplotlib-users).

In any case, this should do what you want:

import numpy as np
import matplotlib.pyplot as plt

fig = plt.figure()
ax = fig.add_subplot(111)

ax.plot(range(5))

ticks = [1.2, 2.3, 3.1, 4]
ax.xaxis.set_ticks(ticks)
ax.xaxis.grid()

plt.show()

Cheers,
Scott



More information about the SciPy-User mailing list