- 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

# Plot horizontal and vertical lines passing through a point that is an intersection point of two lines in Matplotlib

To plot horizontal and vertical lines passing through a point, we can take the following steps

- Set the figure size and adjust the padding between and around the subplots.
- Create two lines using slopes (m1, m2) and intercepts (c1 and c2). Initialize the slopes and intercepts values.
- Create x data points using numpy.
- Plot x, m1, m2, c2 and c1 data points using
**plot()**method. - Using intercepts and slopes values, find the point of intersection.
- Plot horizontal and vertical lines with dotted linestyle.
- Plot xi and yi points on the plot
- 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 m1, c1 = 0.1, 2.0 m2, c2 = 2.0, -3.0 x = np.linspace(-10, 10, 500) plt.plot(x, x * m1 + c1, 'red') plt.plot(x, x * m2 + c2, 'green') plt.xlim(-2, 8) plt.ylim(-2, 8) xi = (c1 - c2) / (m2 - m1) yi = m1 * xi + c1 plt.axvline(x=xi, color='gray', linestyle='--') plt.axhline(y=yi, color='gray', linestyle='--') plt.scatter(xi, yi, color='black') plt.show()

## Output

- Related Articles
- Maximum distinct lines passing through a single point in C
- Program for Point of Intersection of Two Lines in C++
- Find intersection point of lines inside a section in C++
- Fill between two vertical lines in matplotlib
- Matplotlib Plot Lines with Colors through Colormap
- How many lines can pass through a given point?
- How to add vertical lines to a distribution plot (sns.distplot) in Matplotlib?
- Best way to plot an angle between two lines in Matplotlib
- How many lines can pass through(a) one given point? (b) two given points?
- Give the equations of two lines passing through (2,14). How many more such lines are there, and why?
- Write the answer of each of the following questions:(i) What is the name of horizontal and the vertical lines drawn to determine theposition of any point in the Cartesian plane?(ii) What is the name of each part of the plane formed by these two lines?(iii) Write the name of the point where these two lines intersect.
- Give the equations of two lines passing through $(3, 12)$. How many more such lines are there, and why?
- How to plot two dotted lines and set marker using Matplotlib?
- How to remove lines in a Matplotlib plot?
- Removing Horizontal Lines in image (OpenCV, Python, Matplotlib)

Advertisements