- 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
How to shift a graph along the X-axis in matplotlib?
To shift a graph along the X-axis in matplotlib, 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.
- Plot the x and y data points for the original curve.
- Plot the shifted graph, in the range of (1, 1+len(y)) with y data points.
- Place a legend on the figure.
- To display the figure, use show() method.
import numpy as np import matplotlib.pyplot as plt # Set the figure size plt.rcParams["figure.figsize"] = [7.00, 3.50] plt.rcParams["figure.autolayout"] = True # x and y data points x = np.linspace(-5, 5, 100) y = np.sin(x) # Original graph and shifted graph plt.plot(x, y, label='Original Graph') plt.plot(range(1, 1+len(y)), y, label='Shifted Graph') # Place a legend plt.legend(loc='upper right') plt.show()
It will produce the following output
- How to remove relative shift in Matplotlib axis?
- How to customize the X-axis in Matplotlib?
- How to add a second X-axis in Matplotlib?
- How to annotate a range of the X-axis in Matplotlib?
- How to customize X-axis ticks in Matplotlib?
- Transform the element along with x-axis using CSS
- How to change the range of the X-axis and Y-axis in Matplotlib?
- Transform the element along with x-axis and y-axis with CSS
- How to increase the width of the X-axis line for a ggplot2 graph?
- How to add footnote under the X-axis using Matplotlib?
- How to set X-axis values in Matplotlib Python?
- How to set the alignment of the JLabel content along the X axis in Java?
- How to set orientation and split components along x-axis in Java?
- Updating the X-axis values using Matplotlib animation
- Change values on matplotlib imshow() graph axis