- 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 draw a precision-recall curve with interpolation in Python Matplotlib?
To draw a precision-recall curve with interpolation in Python, we can take the following steps −
Steps
Set the figure size and adjust the padding between and around the subplots.
Create r, p and duplicate recall, i data points using numpy.
Create a figure and a set of subplots.
Plot the recall matrix in the range of r.shape.
Plot the r and dup_r data points using plot() method.
To display the figure, use show() method.
Example
import numpy as np import matplotlib.pyplot as plt plt.rcParams["figure.figsize"] = [7.50, 3.50] plt.rcParams["figure.autolayout"] = True r = np.linspace(0.0, 1.0, num=10) p = np.random.rand(10) * (1. - r) dup_p = p.copy() i = r.shape[0] - 2 while i >= 0: if p[i + 1] > p[i]: p[i] = p[i + 1] i = i - 1 fig, ax = plt.subplots() for i in range(r.shape[0] - 1): ax.plot((r[i], r[i]), (p[i], p[i + 1]), 'k-', label='', color='red') ax.plot((r[i], r[i + 1]), (p[i + 1], p[i + 1]), 'k-', label='', color='red') ax.plot(r, dup_p, 'k--', color='blue') plt.show()
Output
It will produce the following output −
- Related Articles
- Draw a parametrized curve using pyplot.plot() in Matplotlib
- Draw parametrized curve using pyplot.plot() in Matplotlib
- How to draw a Bezier Curve with HTML5 Canvas?
- How to fill rainbow color under a curve in Python Matplotlib?
- How to animate a sine curve in Matplotlib?
- Draw a curve connecting two points instead of a straight line in matplotlib
- How to add a cursor to a curve in Matplotlib?
- How to fill color below a curve in Matplotlib?
- Draw Bezier Curve with HTML5 Canvas
- How to measure time with high-precision in Python?
- How to curve text in a polar plot in matplotlib?
- How to draw a quadratic curve on HTML5 Canvas?
- How to remove a specific line or curve in Matplotlib?
- How to get smooth interpolation when using pcolormesh (Matplotlib)?
- How to change the curve using radiobuttons in Matplotlib?

Advertisements