# Invert relationship between units and plotted data Matplotlib

I'm trying to get my plot with Matplotlib to plot as a function of time. My problem is I want the plot to display results from the end of the data (1.6 seconds to 0 seconds) but I want the units on the bottom to go from 0 seconds to 1.6 seconds. How do I change the relationship between the plotted data and the x-axis?

I can't show the plot since I need more reputation to post images.

Thanks for the help!

## Answers

Instead of using plt.plot(x, y), reverse the x values and use plt.plot(x[::-1], y):

import numpy as np import matplotlib.pyplot as plt x = np.linspace(0, 1.6, 100) y = np.exp(-x*3)*x fig, axs = plt.subplots(nrows=2, sharex=True) axs[0].plot(x, y) axs[1].plot(x[::-1], y) plt.xlim(x.min(), x.max()) plt.show()

Here's an example using pyplot.

EDIT: To do what you want, you'll need to modify the plotting call: