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
658 views
in Technique[技术] by (71.8m points)

python - Matplotlib - How to make the marker face color transparent without making the line transparent

I know how to set the transparency of a line in matplotlib. For example, the following code makes the line and the markers transparent.

import numpy as np
import matplotlib.pyplot as plt

vec = np.random.uniform(0, 10, 50)
f = plt.figure(1)
ax = f.add_subplot(111)
ax.plot(vec, color='#999999', marker='s', alpha=0.5)

I want line's alpha=1.0, and marker's face color to be semi-transparent (alpha=0.5). Can this be done in matplotlib?

Thank you.

See Question&Answers more detail:os

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

1 Reply

0 votes
by (71.8m points)

See @Pelson's answer below for the correct way to do this with one line.

You can do this in a hacky way by sticky taping together two independent Line2D objects.

th = np.linspace(0, 2 * np.pi, 64)
y = np.sin(th)
ax = plt.gca()

lin, = ax.plot(th, y, lw=5)
mark, = ax.plot(th, y, marker='o', alpha=.5, ms=10)

ax.legend([(lin, mark)], ['merged'])
plt.draw()

demo figure

see here for explanation


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

...