- 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
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
- Related Articles
- 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?
- How to change the range of the X-axis and Y-axis in Matplotlib?
- How to crop an image along the X-axis using FabricJS?
- How to set X-axis values in Matplotlib Python?
- How to add footnote under the X-axis using Matplotlib?
- How to plot multiple Pandas columns on the Y-axis of a line graph (Matplotlib)?
- How to increase the width of the X-axis line for a ggplot2 graph?
- How to set orientation and split components along x-axis in Java?
- Change values on matplotlib imshow() graph axis
- How to place X-axis grid over a spectrogram in Python Matplotlib?
- How to set the alignment of the JLabel content along the X axis in Java?