Issue
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.
Something like this might be helpful if it were in python instead of JavaScript: Have text displayed instead of numerical values on y axis
Solution
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()
Answered By - tmdavison
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.