How to plot 1-d data at given y-value with pylab

Staven already edited his post to include how to plot the values along y-value 1, but he was using Python lists.

A variant that should be faster (although I did not measure it) only uses numpy arrays:

import numpy as np
import matplotlib.pyplot as pp
val = 0. # this is the value where you want the data to appear on the y-axis.
ar = np.arange(10) # just as an example array
pp.plot(ar, np.zeros_like(ar) + val, 'x')
pp.show()

As a nice-to-use function that offers all usual matplotlib refinements via kwargs this would be:

def plot_at_y(arr, val, **kwargs):
    pp.plot(arr, np.zeros_like(arr) + val, 'x', **kwargs)
    pp.show()

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)