adds rule to select fewer ticks in sqrt scale for bokeh and plotly#189
adds rule to select fewer ticks in sqrt scale for bokeh and plotly#189aloctavodia merged 4 commits intoarviz-devs:mainfrom The-Broken-Keyboard:fewer_ticks_in_sqrt_scale
Conversation
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #189 +/- ##
==========================================
- Coverage 72.52% 72.49% -0.03%
==========================================
Files 35 35
Lines 4026 4029 +3
==========================================
+ Hits 2920 2921 +1
- Misses 1106 1108 +2 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
|
This will still be problematic if frequencies have large values, for instance dt = azb.from_dict({ |
|
Yeah, true. I just realised that it will be problematic if maximum y value is high. To handle this, Can we have a default fix number of ticks which we can determine dynamically between minimum y value and maximum y value? So even for high values, the number of ticks can be fixed. Or else, we can have a dynamic rule which will determine the good number of ticks for a given range of values. Then determining those ticks won't be a difficult task to do.... What do you suggest @aloctavodia ? |
|
It is probably a good idea to check what matplotlib does by default and implement something similar. |
|
Heyy @aloctavodia |
|
Fixing the number of ticks like Matplotlib seems reasonable. |
aloctavodia
left a comment
There was a problem hiding this comment.
Plotly is missing the highest ytick, and sometimes cropping the highest value . See for example
dt = azb.from_dict({
'observed_data': {"obs":pz.Poisson(2).rvs(100, random_state=1)},
'posterior_predictive': {"obs":pz.Poisson(2).rvs((2, 1000, 100), random_state=1)}
})
| num_ticks = 5 | ||
| num_ticks = min(num_ticks, math.ceil(((y_max * y_max) - (y_min * y_min)) / 2)) | ||
| step_size = round(((y_max * y_max) - (y_min * y_min)) / num_ticks) | ||
| start_tick = round(y_min * y_min) | ||
| end_tick = step_size * num_ticks | ||
|
|
There was a problem hiding this comment.
| num_ticks = 5 | |
| num_ticks = min(num_ticks, math.ceil(((y_max * y_max) - (y_min * y_min)) / 2)) | |
| step_size = round(((y_max * y_max) - (y_min * y_min)) / num_ticks) | |
| start_tick = round(y_min * y_min) | |
| end_tick = step_size * num_ticks | |
| num_ticks = 5 | |
| num_ticks = min(num_ticks, math.ceil((y_max**2 - y_min**2) / 2)) | |
| step_size = math.ceil((y_max**2 - y_min**2) / num_ticks) | |
| start_tick = math.ceil(y_min**2) | |
| end_tick = step_size * num_ticks |
| tickvals_transformed = [] | ||
| for i in range(int(round(y_max * y_max)) + 1): | ||
| tickvals_transformed.append(np.sqrt(i)) | ||
| for i in range(start_tick, end_tick, step_size): |
There was a problem hiding this comment.
| for i in range(start_tick, end_tick, step_size): | |
| tickvals_transformed = [i**0.5 for i in range(start_tick, end_tick, step_size)] |
| num_ticks = 5 | ||
| num_ticks = min(num_ticks, math.ceil(max_y / 2)) | ||
| step_size = round(math.ceil(max_y) / num_ticks) | ||
| end_tick = num_ticks * step_size | ||
| start_tick = 0 |
There was a problem hiding this comment.
| num_ticks = 5 | |
| num_ticks = min(num_ticks, math.ceil(max_y / 2)) | |
| step_size = round(math.ceil(max_y) / num_ticks) | |
| end_tick = num_ticks * step_size | |
| start_tick = 0 | |
| num_ticks = min(5, math.ceil(max_y / 2)) | |
| step_size = round(math.ceil(max_y) / num_ticks) | |
| end_tick = num_ticks * step_size | |
| ticks = [i**0.5 for i in range(0, end_tick + 1, step_size)] |
| ticks = [] | ||
| if max_y > 0: | ||
| for i in range(math.ceil(max_y) + 1): | ||
| for i in range(start_tick, end_tick + 1, step_size): |
There was a problem hiding this comment.
| for i in range(start_tick, end_tick + 1, step_size): |
Yeah, I kept that knowingly because the circular dots in plotly ( which are little bigger in size than a normal dot ) would get cut if they fall on value 0. I can remove it or I can reduce the gap as well. Whatever you suggest @aloctavodia . like this would happen without space: In Bokeh and Matplotlib the dots are not circular with bigger size so it looks good there. |
|
could you please update the images in the PR description? |
|
@aloctavodia actually I am currently in a class so couldn't update image when you asked. |
|
Sure, no rush. Thanks |




closes #184
Instead of adding all integer ticks within range [0,max_y_value], new rule adds fewer ticks in same range.
The rule is similar to Matplotlib's autolocator's rule, it calculates the possible no. of ticks first in the given range, then it clips that value between 1 to 5. Then based on the number of ticks it calculates step size to put ticks across the axis.
By default the number of ticks is 5 ( didn't keep it 9, which matplotlib has, because in square root scale higher value ticks are placed more closer so it looks little congested for more number of ticks ).
Bokeh:
Plotly:
📚 Documentation preview 📚: https://arviz-plots--189.org.readthedocs.build/en/189/