![Trending Articles on Technical and Non Technical topics](/images/trending_categories.jpeg)
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
Advertisements