X Tutup
Skip to content

How to rotate secondary y axis label so it doesn't overlap with y-ticks, matplotlib #5920

@hselbie

Description

@hselbie

figure_2
I am trying to rotate my secondary y-label to 270 degrees, but when I do this passing the rotate=270 argument it overlaps my y-tick text? I can fix the problem with labelpad but I think this might be a bug, perhaps using pandas?

fig, ax = plt.subplots()

ax.plot(df.index,df.tripTime,label='Fishing Effort', marker='D')
ax2=ax.twinx()
ax2.plot(tr.index,tr.cost, 'g',label='Fuel Expenditure', marker='d')

lines = ax.get_lines() + ax2.get_lines()
ax.legend(lines,[line.get_label() for line in lines], loc='lower left')
ax.set_ylim((0, 18))

ax2.set_ylabel('Cost ($)',color='g', rotation=270)

for tl in ax2.get_yticklabels():
tl.set_color('g')

ax.set_ylabel('Fishing Effort (hrs)')
ax.set_xlabel('Time (days)')
plt.show()

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      X Tutup