79573133

Date: 2025-04-14 12:26:17
Score: 1
Natty:
Report link

Just adding to Floriaan's answer, I had noticed that the function did not work well for inputs round_to greater than 1, so I added a small checkup:

def calculate_ticks(ax, ticks, round_to=0.1, center=False):
    upperbound = np.ceil(ax.get_ybound()[1]/round_to)
    lowerbound = np.floor(ax.get_ybound()[0]/round_to)
    dy = upperbound - lowerbound
    # The added part:
    if round_to > 1:
        fit = np.floor(dy/(ticks - 1))
    else:
        fit = np.floor(dy/(ticks - 1)) + 1
    dy_new = (ticks - 1)*fit
    if center:
        offset = np.floor((dy_new - dy)/2)
        lowerbound = lowerbound - offset
    values = np.linspace(lowerbound, lowerbound + dy_new, ticks)
    return values*round_to
Reasons:
  • Blacklisted phrase (1): did not work
  • Long answer (-0.5):
  • Has code block (-0.5):
  • Low reputation (1):
Posted by: Filip Maletic