user2539738 user2539738 - 3 months ago 19
Python Question

plotting vertical bars instead of points, plot_date

I want to plot vertical bars instead of points. The actual data I have are irregularly spaced, so this will help visualize gaps more easily.
When I try to plot it, the best I can do are points, which don't increase in size as you zoom in!

import matplotlib
from matplotlib import pyplot as plt
import datetime

XX = [datetime.date.today()+datetime.timedelta(x) for x in range(10)]
YY = range(10)
plt.plot_date(XX,YY,'o')


enter image description here

enter image description here

Any ideas on how I can make taller/bigger (but not wider!) points?

tom tom
Answer

You can use ax.vlines to plot a collection of vertical lines.

You can adjust ymin and ymax to suit your data.

import matplotlib
from matplotlib import pyplot as plt
import datetime

XX = [datetime.date.today()+datetime.timedelta(x) for x in range(10)]

plt.vlines(XX, ymin=0, ymax=1, linewidth=5)

plt.show()

enter image description here