- 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 plot scatter masked points and add a line demarking masked regions in Matplotlib?
To plot scattered masked points and add a line to demark the masked regions, we can take the following steps.
Steps
- Set the figure size and adjust the padding between and around the subplots.
- Create N, r0, x, y, area, c, r, area1and area2 data points using numpy.
- Plot x and y data points using scatter() method.
- To demark the maked regions, plot the curve using plot() method.
- 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 = 100 r0 = 0.6 x = 0.9 * np.random.rand(N) y = 0.9 * np.random.rand(N) area = (20 * np.random.rand(N))**2 c = np.sqrt(area) r = np.sqrt(x ** 2 + y ** 2) area1 = np.ma.masked_where(r < r0, area) area2 = np.ma.masked_where(r >= r0, area) plt.scatter(x, y, s=area1, marker='^', c=c) plt.scatter(x, y, s=area2, marker='o', c=c) theta = np.arange(0, np.pi / 2, 0.01) plt.plot(r0 * np.cos(theta), r0 * np.sin(theta)) plt.show()
Output
- Related Articles
- How to plot masked and NaN values in Matplotlib?
- Plot scatter points using plot method in Matplotlib
- How to plot additional points on the top of a scatter plot in Matplotlib?
- Plotting a masked surface plot using Python, Numpy and Matplotlib
- How to draw an average line for a scatter plot in MatPlotLib?
- Plot scatter points on polar axis in Matplotlib
- Plot scatter points on 3d plot without axes and grids in Matplotlib
- How to plot scatter points in a 3D figure with a colorbar in Matplotlib?
- Connecting two points on a 3D scatter plot in Python and Matplotlib
- How to plot scatter points with increasing size of marker in Matplotlib?
- How to animate a scatter plot in Matplotlib?
- How to use different markers for different points in a Pylab scatter plot(Matplotlib)?
- Adding a line to a scatter plot using Python's Matplotlib
- How to annotate the points on a scatter plot with automatically placed arrows in Matplotlib?
- Plot scatter points on a 3D projection with varying marker size in Matplotlib

Advertisements