I’m trying to make a simple line plot where all the values around very close to 1. However, when I plot it the y-axis gets shifted down so all values are centered around 0. It indicates this with a +1
at the top of the y-axis. How do I make it stop shifting the y-axis?
Simple reproducer:
import numpy as np
import datetime
vals = np.random.uniform(0.9999, 1.0001, 100)
dates = [datetime.datetime.now() + datetime.timedelta(minutes=i) for i in range(len(vals))]
plt.plot(dates, vals)
plt.show()
This code results in the following graph. It looks the same through Pycharm and when run from the terminal using PyQt6.
1
You can adjust the format like this:
plt.ticklabel_format(axis='y', useOffset=False)
see this documentation: https://matplotlib.org/3.1.1/api/_as_gen/matplotlib.axes.Axes.ticklabel_format.html
import numpy as np
import datetime
vals = np.random.uniform(0.9999, 1.0001, 100)
dates = [datetime.datetime.now() + datetime.timedelta(minutes=i) for i in range(len(vals))]
plt.plot(dates, vals)
plt.ticklabel_format(axis='y', useOffset=False)
plt.show()
1