0

I would like to generate a y-axis like shown in the below plot in Python. I guess using matplotlib should help, but i cant figure out the code needed for that.

enter image description here

5
  • 1
    You can use ticks on the y axis Commented Nov 16, 2016 at 6:51
  • Hi Achilles. How exactly do I do this? Commented Nov 16, 2016 at 7:19
  • Could you show the values of your Y axis? Commented Nov 16, 2016 at 7:22
  • Ok Let me show you an example which will help you. Commented Nov 16, 2016 at 7:25
  • 99,99990134 99,99901344 99,99765819 99,99359183 99,99023872 99,98895495 99,98977619 99,99276222 99,99480763 Commented Nov 16, 2016 at 7:26

2 Answers 2

1

You need a logarithmic scale but this usually starts from zero. So the trick is to plot (1 - y) instead of y. Then you set the ticks and their labels. My suggestion (the values are < 1, but you can easily scale to 100):

# Some data
x = np.array([1, 2, 3, 4, 5])
y = np.array([0.99, 0.999, 0.9923, 0.995, 0.997])

fig, ax = plt.subplots()

# Plot the inverted data with log scale
ax.plot(x, 1 - y)
ax.set_ylim(0.1, 0.001)
ax.set_yscale("log")

# Now set what ticks (in transformed y) and what labels to use
ticks = np.array([0.0001, 0.001, 0.01, 0.1])
tick_labels = (1 - ticks) * 100

ax.set_yticks(ticks)
ax.set_yticklabels(tick_labels)
ax.set_ylabel("Some value in %")
# And you're done :-)
Sign up to request clarification or add additional context in comments.

Comments

1

Let's say for example you have a list for your y axis:

y = [1,2,3,4]

You can add ticks on it like this:

plt.yticks([90.0,99.0,99.9,99.99])

Thus changing the y axis label.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.