- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
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.
Steps
- Set the figure size and adjust the padding between and around the subplots.
- Create a figure and a set of subplots using subplots() method.
- Set different values for edge and face color opacity.
- Add a rectangel patch using add_patch() method.
- To display the figure, use show() method.
Example
from matplotlib import pyplot as plt, patches plt.rcParams["figure.figsize"] = [7.50, 3.50] plt.rcParams["figure.autolayout"] = True figure, ax = plt.subplots() edge_color_opacity = 1 # 0<val<1 face_color_opacity = 0.75 # 0<val<1 ax.add_patch(patches.Rectangle((.25, .25), .50, .50, edgecolor=(1, 0, 0, edge_color_opacity), facecolor=(0, 1, 0, face_color_opacity), linewidth=2)) plt.show()
Output
- Related Articles
- How to label a patch in matplotlib?
- How to control the border of a bar patch in matplotlib?
- How to plot a 3D patch collection in matplotlib?
- Plot a circle with an edgecolor and hatch in Matplotlib
- How to set the opacity of a Circle using FabricJS?
- How to set the opacity of a Rectangle using FabricJS?
- How to set opacity of a text canvas using Fabric.js?
- Plot a rectangle with an edgecolor in Matplotlib
- Plot a circle with an edgecolor in Matplotlib
- How to rotate the rectangle patch in a plot using Matplotlib?
- How to set the opacity of Triangle using FabricJS?
- How to set the opacity of Textbox using FabricJS?
- How to set the opacity of Image using FabricJS?
- How to set the opacity of an Ellipse using FabricJS?
- How to Set opacity for View in Android?

Advertisements