Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
426 views
in Technique[技术] by (71.8m points)

python - Matplotlib Plot Dashed Circles (using plt.plot instead of plt.scatter)

Given the following:

import matplotlib.pyplot as plt 
import numpy as np 
#http://matplotlib.org/api/pyplot_api.html#matplotlib.pyplot.scatter
x = np.random.randn(60) 
y = np.random.randn(60)
x2 = np.random.randn(60)
y2 = np.random.randn(60)

plt.plot(x, y, marker='o', markeredgecolor='r', linestyle='none', markerfacecolor='none')
plt.plot(x2, y2, marker='o', markeredgecolor='r', linestyle='none', markerfacecolor='none')
plt.show()

I'd like for x2 and y2 to be plotted as dashed (or even dotted) circles. I am avoiding the use of plt.scatter because the rest of my script works with plt.plot much better. Here's what I'm looking for: enter image description here

Thanks in advance!

FYI: Here's the actual chart I created. I just used hexagons for now to signify the different data (future data).

enter image description here

The custom legend and plotting over groups of rows in a pandas Data Frame add layers of complexity that I couldn't overcome with plt.scatter.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

You can use the dotted circle (ur'$u25CC$') from the STIX font (pdf with all symbols here) using mathtext functionality

 plt.plot(x, y, marker=ur'$u25CC$', markerfacecolor='r', 
                markeredgecolor='r', markersize=30, linestyle='none', )

Note, that markerfacecolor is set to a color as well.

A drawback is that they need a certain size to be distinguishable from a closed circle.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...