- 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 put the Origin at the center of the cos curve in a figure in Python Matplotlib?
To put the Origin at the center of the cos curve in a figure, we can take the following steps −
Set the figure size and adjust the padding between and around the subplots.
Create x and y data points using numpy.
Set the position of the axes using spines, top, left, right and bottom.
Plot x and y data points using plot() method.
Set the title of the plot.
To display the figure, use show() method.
Example
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(-5, 5, 100) y = np.cos(x) ax = plt.gca() ax.spines['top'].set_color('none') ax.spines['left'].set_position('zero') ax.spines['right'].set_color('none') ax.spines['bottom'].set_position('zero') plt.plot(x, y) plt.title("$\bf{y=cos(x)}$") plt.show()
Output
- Related Articles
- How to put the title at the bottom of a figure in Matplotlib?
- How to put text at the corner of an equal aspect figure in Python/Matplotlib?
- How do I extend the margin at the bottom of a figure in Matplotlib?
- How to change the curve using radiobuttons in Matplotlib?
- How to fill rainbow color under a curve in Python Matplotlib?
- How to fill color above the curve in Matplotlib Program?
- Fill the area under a curve in Matplotlib python on log scale
- How to animate a sine curve in Matplotlib?
- How to draw a precision-recall curve with interpolation in Python Matplotlib?
- How to draw axis in the middle of a figure in Matplotlib?
- How to set the margins of a Matplotlib figure?
- Filling the region between a curve and X-axis in Python using Matplotlib
- How to add a cursor to a curve in Matplotlib?
- How to set the current figure in Matplotlib?
- How to put a title for a curved line in Python Matplotlib?

Advertisements