Matplotlib Plot Dashed Circles

2019-09-14 06:16发布

问题:

Given the following:

import matplotlib.pyplot as plt 
import numpy as np 

x = np.random.randn(60) 
y = np.random.randn(60)
x2 = np.random.randn(60)
y2 = np.random.randn(60)

plt.scatter(x, y, s=80, facecolors='none', edgecolors='r')
plt.scatter(x2, y2, s=80, facecolors='none', edgecolors='r')
plt.show()

How would I plot this same data with dashed circles instead (where the outline of each circle is dashed instead of solid) for x 2 and y2 only?

Thanks in advance!

Update: I know this can be done with patches as in here, but I need it to be done via plt.scatter if possible because I will also be plotting another set of circles on the same plot and using patches messed with the chart dimensions (was way too thin).

回答1:

Pass linestyle='--' to scatter.

plt.scatter(x, y, s=80, facecolors='none', edgecolors='r')
plt.scatter(x2, y2, s=80, facecolors='none', edgecolors='r',
            linestyle='--')

For that marker size I would rather use linestyle=':' though.