- Trending Categories
- Data Structure
- Operating System
- C Programming
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Draw a curve connecting two points instead of a straight line in matplotlib
To draw a curve connecting two points instead of a straight line in matplotlib, we can take the following steps −
- Set the figure size and adjust the padding between and around the subplots.
- Define a draw_curve() method to make a curve with a mathematical expression.
- Plot point1 and point2 data points.
- Plot x and y data points returned from the draw_curve() method.
- To display the figure, use show() method.
import matplotlib.pyplot as plt import numpy as np plt.rcParams["figure.figsize"] = [7.00, 3.50] plt.rcParams["figure.autolayout"] = True def draw_curve(p1, p2): a = (p2 - p1) / (np.cosh(p2) - np.cosh(p1)) b = p1 - a * np.cosh(p1) x = np.linspace(p1, p2, 100) y = a * np.cosh(x) + b return x, y p1 = [0, 1] p2 = [1, 2] x, y = draw_curve(p1, p2) plt.plot(p1, p1, 'o') plt.plot(p2, p2, 'o') plt.plot(x, y) plt.show()
It will produce the following output
- Draw a parametrized curve using pyplot.plot() in Matplotlib
- Connecting two points on a 3D scatter plot in Python and Matplotlib
- Draw parametrized curve using pyplot.plot() in Matplotlib
- Program to find out the number of integral coordinates on a straight line between two points in Python
- Represent a Given Set of Points by the Best Possible Straight Line in C++
- How to remove a specific line or curve in Matplotlib?
- Program to check whether list of points form a straight line or not in Python
- How to draw a line outside of an axis in Matplotlib?
- How to draw a precision-recall curve with interpolation in Python Matplotlib?
- How to draw the largest polygon from a set of points in matplotlib?
- How do you create line segments between two points in Matplotlib?
- How can I draw a scatter trend line using Matplotlib?
- Straight Line Method of Calculating Depreciation
- Check if it is possible to draw a straight line with the given direction cosines in Python
- Check If It Is a Straight Line in C++