0

I want my x-axis to be a thick line, so I created an axhline at y=0. However autoscale considers the line when it calculates the y-axis range. I want it to ignore the axhline at 0, and focus on the plotted data (even if that means axhline does not show in that particular instance). I created a very simple sample case below (where I would prefer autoscale to pick a y-axis range of something closer to 12-18:

import matplotlib.pyplot as plt
import numpy as np

x = [1, 2, 3, 4, 5, 6, 7]
y = [15, 16, 13, 17, 18, 14, 13]

fig, ax = plt.subplots()

ax.axhline(linewidth=2, color='k', zorder=1)
ax.plot(x, y)

enter image description here

1 Answers1

1

I would suggest not plotting the extra line, allowing it to autoscale normally. Here is an example of how to change the axes line widths, where you put in any number, and can change the for loop to just one axis. Pulled from this previous question.

for axis in ['top','bottom','left','right']:
  ax.spines[axis].set_linewidth(0.5)
cmay
  • 153
  • 6