Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I plot a style like gnuplot's 'with impulses' with matplotlib?

I'd like to create a plot like the one below with python/pandas/matplotlib. The upper clip is no problem, but I haven't been able to get a plot like the lower clip to work. I can do it in gnuplot where the equivalent plot style is 'with impulses'. Is this possible with matplotlib? If it is not possible with matplotlib is there another python graphics package that would work?

The gnuplot style for the lower clip is 'with impulses'

like image 668
John Avatar asked Feb 04 '23 06:02

John


1 Answers

The easiest way to create such a plot is to use pyplot.stem. An example can be found here.

import matplotlib.pyplot as plt
import numpy as np

x = np.linspace(0.1, 6*np.pi, 50)
plt.stem(x, np.cos(x)+1, linefmt='g-', markerfmt=' ')
plt.stem(x, -np.sin(x)-1, linefmt='r-', markerfmt=' ', basefmt="gray")

plt.show()

enter image description here

Another option is to use pyplot.vlines.

like image 70
ImportanceOfBeingErnest Avatar answered Feb 06 '23 20:02

ImportanceOfBeingErnest