0

How can I change my plot so that the y axis label is moved slightly to the left, so it does not overlap with y axis tick labels?

Here is the code I used to create my plot:

import matplotlib.pyplot as plt
import seaborn as sns

sns.lineplot(data=reefs, x='Step', y='total_mm_growth', hue='AgentID', palette= "colorblind")
plt.xlabel('Step')
plt.ylabel('Growth (mm)', rotation = 0)
plt.legend(title="Reef ID")
plt.title("Modeled Change In Reef Elevation Over 5 Years")

enter image description here

I tried using solutions with ax.yaxis.set_label_coords(-1, 0) but I get the error 'tuple' object has no attribute 'yaxis'. I'm new to python and have no idea what I'm doing.

Trenton McKinney
  • 56,955
  • 33
  • 144
  • 158
ifoxfoot
  • 195
  • 7
  • 1
    `ax = sns.lineplot(...)`? Not sure where you got `ax` from to get a tuple, but [`sns.lineplot`](https://seaborn.pydata.org/generated/seaborn.lineplot.html) returns the matplotlib `Axes`. – BigBen May 05 '23 at 15:47
  • OHHHHH! Okay I got it now, thank you @BigBen. I was using `ax = plt.subplots` because I copied it from another SO post. – ifoxfoot May 05 '23 at 15:53
  • 1
    That would be `fig, ax = plt.subplots()`. – BigBen May 05 '23 at 15:54
  • `plt.ylabel('Growth (mm)', rotation=0, labelpad=50)` [code and plot](https://i.stack.imgur.com/8aeRY.png) – Trenton McKinney May 05 '23 at 19:40

0 Answers0