How to parametrize markers' color/alpha/radius with matplotlib's plot_date

I am trying to create a timeseries plot with matplotlib's plot_date(). One of the series I want to overlay has two scalar values per single time point. I would like to map one of these scalars to y axis, and the other one to some property of the marker, such as alpha value, color, or size (radius in case of circular markers). There are examples of similar effects but with scatter plots. Is there a clever way to achieve such effect with plot_date?

Upvotes: 1

Views: 340

Answers (1)

ImportanceOfBeingErnest
ImportanceOfBeingErnest

Reputation: 339430

There is no reason to use plot_date here. Instead use a scatter plot. Use the scatter's c argument to produce the coloring. A minimal example:

import numpy as np
import datetime
import matplotlib.pyplot as plt

base = datetime.datetime.today()
x = [base - datetime.timedelta(days=x) for x in np.random.randint(0,60, size=36)]
y = np.random.rand(36)
z = np.random.rand(36)
plt.scatter(x,y, c=z)

plt.gcf().autofmt_xdate()
plt.show()

enter image description here

Upvotes: 1

Related Questions