I am trying to plot a set of triangles with different orientations and sizes. The inner overlapped shape is what i wanted, which is the darkest area. But when I set opacity (alpha) in mpatches.RegularPolygon, the edges become transparent too. How can I solve this problem? Thank you!
How to set different opacity of edgecolor and facecolor of a patch in Matplotlib? To set different opacity of edge and face color, we can use a color tuple and the 4th index of the tuple could set the opacity value of the colors.
Show activity on this post. per the documentation, edgecolors is default to None, which got override by matplotlib.rcParams default settings, which is transparent. So either do: p = PatchCollection (patches, edgecolor='r', alpha=0.4) ax.add_collection (p)
Matplotlib indexes color at draw time and defaults to black if cycle does not include color. "Red", "Green", and "Blue" are the intensities of those colors. In combination, they represent the colorspace.
The color (s) for bar edges. The parameter takes a color or list of colors. If a color value is given for edgecolor, then all the bars will get the same color for their edges. Note: If we are providing a list of colors for edgecolor parameter, the length of this list of colors should match the length of x and height.
You should perhaps post some code to make your meaning clear, but from what I understand, you could set the facecolor
and edgecolor
separately as (R,G,B,alpha) tuples and set alpha
for the edgecolor
equal to 1 to make it opaque if that's what you want. For example,
import matplotlib.pyplot as plt
from matplotlib.patches import Polygon
fig = plt.figure()
ax = fig.add_subplot(111, aspect='equal')
triangle1 = Polygon(((0.05,0.1), (0.396,0.1), (0.223, 0.38)),
fc=(1,0,0,0.5), ec=(0,0,0,1), lw=2)
triangle2 = Polygon(((0.2,0.2), (0.5,0.4), (0.3, 0.6)),
fc=(1,0,0,0.5), ec=(0,0,0,1), lw=2)
ax.add_artist(triangle1)
ax.add_artist(triangle2)
plt.show()
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With