- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
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 legend marker size and alpha in Matplotlib?
To set legend marker size and alpha in matplotlib, we can take the following steps −
Steps
Set the figure size and adjust the padding between and around the subplots.
Initialize a variable N to store the number of sample data.
Plot the x and y data points with marker="*".
Place a legend on the figure.
Set the marker size and alpha value of the marker.
To display the figure, use show() method.
Example
import matplotlib.pyplot as plt import numpy as np plt.rcParams["figure.figsize"] = [7.50, 3.50] plt.rcParams["figure.autolayout"] = True N = 10 x = np.random.rand(N) y = np.random.rand(N) line, = plt.plot(x, y, marker='*', markersize=20, markeredgecolor='black', alpha=0.4, ls='none', label='Random Data') legend = plt.legend(loc='upper right') legend.legendHandles[0]._legmarker.set_markersize(15) legend.legendHandles[0]._legmarker.set_alpha(1) plt.show()
Output
It will produce the following output −
- Related Articles
- How to set the font size of Matplotlib axis Legend?
- How to change the marker size with pandas.plot() in Matplotlib?
- How to plot two dotted lines and set marker using Matplotlib?
- How to plot scatter points with increasing size of marker in Matplotlib?
- How to adjust the size of a Matplotlib legend box?
- How to increase the font size of the legend in my Seaborn plot using Matplotlib?
- How to set a title above each marker which represents a same label in Matplotlib?
- How to add legend to imshow() in Matplotlib?
- How to position and align a Matplotlib figure legend?
- Plot scatter points on a 3D projection with varying marker size in Matplotlib
- Set variable point size in Matplotlib
- How to show legend elements horizontally in Matplotlib?
- How to change the legend fontname in Matplotlib?
- How to create a draggable legend in Matplotlib?
- How to set the matplotlib figure default size in ipython notebook?

Advertisements