0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 1 year has passed since last update.

[matplotlib]折れ線グラフの線だけ透明にする

Posted at

折れ線グラフのマーカは不透明で、線のみ透明に

plotalphaを指定すると、線とマーカが両方透明度が設定される。

Matplotlib - How to make the marker face color transparent without making the line transparent
を見ると個別に設定できる旨があったが、色は指定したくなかった。

get_color, get_markerfacecolor で色は取れるので、to_rgbで16進文字列をRGBに変換して再指定でできた。

import numpy as np
import matplotlib.pyplot as plt
from matplotlib.colors import to_rgb

plt.figure()
plt.plot(np.random.randn(10), np.random.randn(10), "*")
l, = plt.plot(range(10), np.random.randn(10), "+-")

print("before", l.get_color(), l.get_markerfacecolor())

l.set_color((*to_rgb(l.get_color()), 0.1))
l.set_markerfacecolor((*to_rgb(l.get_markerfacecolor()), 1))

print("after", l.get_color(), l.get_markerfacecolor())

plt.show()

image.png

**alphaでマーカだけ、線だけ透明度設定できればいいのに。​

0
0
1

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?