1

I'm wondering if it is possible to shift the graph only to the left for the following plot graph.

import matplotlib
import matplotlib.pyplot as plt
import numpy as np

# Data for plotting
t = np.arange(0.0, 2.0, 0.01)
s = 1 + np.sin(2 * np.pi * t)

fig, ax = plt.subplots()
ax.plot(t, s)

ax.set(xlabel='time (s)', ylabel='voltage (mV)',
   title='About as simple as it gets, folks')
ax.grid()

fig.savefig("test.png")
plt.show()

Pyh

I want to leave the x ticks the same but want to shift the graph so that the starting point of the graph is on y-axis. Any suggestions?

Thank you in advance.

joo hwan kwon
  • 119
  • 2
  • 8
  • 1
    `plt.xlim(t.min(), t.max())`? `ax.autoscale(enable=True, axis='x', tight=True)` as in [this post](https://stackoverflow.com/questions/37558329/matplotlib-set-axis-tight-only-to-x-or-y-axis/37561377)? – JohanC Mar 18 '20 at 00:04
  • plt.autoscale(enable=True, axis='x', tight=True) – joo hwan kwon Mar 18 '20 at 00:28

1 Answers1

1

You can make the starting point of the line lie on the y-axis by changing the limits on the x-axis with

ax.set_xlim(xmin=0)
S95
  • 21
  • 4