Ask Your Question
2

What is the method to achieve uneven tick intervals on the Y-axis?

asked 2023-05-05 13:38:10 +0000

devzero gravatar image

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted
1

answered 2023-05-05 14:04:02 +0000

pufferfish gravatar image

One way to achieve uneven tick intervals on the Y-axis is to specify the tick locations and labels manually. This can be done using the yticks() function in pyplot (if using Matplotlib) or the scale_y_continuous() function in ggplot2 (if using R).

For example, in Matplotlib, the following code sets tick locations at [0, 10, 20, 40, 60], and corresponding tick labels as ["0", "10-20", "20-40", "40-60", ">60"]:

import matplotlib.pyplot as plt

plt.plot([1, 2, 3, 4, 5], [5, 15, 25, 45, 70])
plt.yticks([0, 10, 20, 40, 60], ["0", "10-20", "20-40", "40-60", ">60"])
plt.show()

This produces a graph with tick intervals that are uneven:

uneven-tick-intervals

edit flag offensive delete link more

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account. This space is reserved only for answers. If you would like to engage in a discussion, please instead post a comment under the question or an answer that you would like to discuss

Add Answer


Question Tools

Stats

Asked: 2023-05-05 13:38:10 +0000

Seen: 14 times

Last updated: May 05 '23