Mohammad Athar
Mohammad Athar

Reputation: 1980

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?

Upvotes: 2

Views: 956

Answers (2)

JessieQuick
JessieQuick

Reputation: 51

Did you mean bars like this?

enter image description here

And here is the code:

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,'|')
plt.show()

You can change the shape of your plot by changing the third argument you pass in the plt.plot_date function. In your code you are passing an 'o' that is why you get a dot. Here i pass bar to plot bar.

Upvotes: 0

tmdavison
tmdavison

Reputation: 69136

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

Upvotes: 1

Related Questions