- Trending Categories
- Data Structure
- Operating System
- MS Excel
- C Programming
- 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
Show the origin axis (x,y) in Matplotlib plot
To show the origin, we can take the following Steps −
Create the points x, y1 and y2 using numpy.
Plot the sine and cosine curves using plot() methods.
Plot the vertical line, i.e., x=0.
Plot the horizontal line, i.e., y=0.
Intersection point of (Step 3 and 4), could be the origin.
To display the label of lines, use legend() method.
To display the figure, use show() method.
import numpy as np from matplotlib import pyplot as plt plt.rcParams["figure.figsize"] = [7.50, 3.50] plt.rcParams["figure.autolayout"] = True x = np.linspace(1, 10, 50) y1 = np.sin(x) y2 = np.cos(x) plt.plot(x, y1, c="orange", label="y=sin(x)") plt.plot(x, y2, c="green", label="y=cos(x)") plt.axvline(x=0, c="red", label="x=0") plt.axhline(y=0, c="yellow", label="y=0") plt.legend() plt.show()
- Related Articles
- Draw axis lines or the origin for Matplotlib contour plot.
- Plot a histogram with Y-axis as percentage in Matplotlib
- Moving X-axis in Matplotlib during real-time plot
- How to change the range of the X-axis and Y-axis in Matplotlib?
- Overlapping Y-axis tick label and X-axis tick label in Matplotlib
- Plot two horizontal bar charts sharing the same Y-axis in Python Matplotlib
- How to show date and time on the X-axis in Matplotlib?
- Show decimal places and scientific notation on the axis of a Matplotlib plot
- Adjusting the spacing between the edge of the plot and the X-axis in Matplotlib
- Adding caption below X-axis for a scatter plot using Matplotlib
- How do I plot multiple X or Y axes in Matplotlib?
- How to plot two Pandas time series on the same plot with legends and secondary Y-axis in Matplotlib?
- How to plot data against specific dates on the X-axis using Matplotlib?
- How to force Matplotlib to show the values on X-axis as integers?
- How to plot a smooth 2D color plot for z = f(x, y) in Matplotlib?