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.
-
1You can use ticks on the y axisTaufiq Rahman– Taufiq Rahman2016-11-16 06:51:09 +00:00Commented Nov 16, 2016 at 6:51
-
Hi Achilles. How exactly do I do this?Benjo– Benjo2016-11-16 07:19:45 +00:00Commented Nov 16, 2016 at 7:19
-
Could you show the values of your Y axis?Taufiq Rahman– Taufiq Rahman2016-11-16 07:22:52 +00:00Commented Nov 16, 2016 at 7:22
-
Ok Let me show you an example which will help you.Taufiq Rahman– Taufiq Rahman2016-11-16 07:25:01 +00:00Commented Nov 16, 2016 at 7:25
-
99,99990134 99,99901344 99,99765819 99,99359183 99,99023872 99,98895495 99,98977619 99,99276222 99,99480763Benjo– Benjo2016-11-16 07:26:58 +00:00Commented Nov 16, 2016 at 7:26
Add a comment
|
2 Answers
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 :-)
