1

This is my current graph made with matplotlib. Is there a way to make the y-axis say "Down x%"

For instance instead of "-10%" I want it to say "Down 10%". And the same for the rest of the ticks.

enter image description here

Something like this might be helpful if it were in python instead of JavaScript: Have text displayed instead of numerical values on y axis

tmdavison
  • 64,360
  • 12
  • 187
  • 165
filifunk
  • 543
  • 1
  • 6
  • 18

1 Answers1

3

You can use a FuncFormatter to define any format you like for the ticks.

In this case, you could use a conditional statement to change the minus sign to "Down" only when the value is less than zero.

import matplotlib.pyplot as plt

x = [0, 5, 10]
y = [0, -25, -50]

fig, ax = plt.subplots()

ax.plot(x, y)

def myformat(x, pos):
    if x >= 0:
        return "{}%".format(x)
    else:
        return "Down {}%".format(-x)

ax.yaxis.set_major_formatter(plt.FuncFormatter(myformat))

plt.tight_layout()
plt.show()

enter image description here

tmdavison
  • 64,360
  • 12
  • 187
  • 165