I am using plotnine library to visualise data. I use for loop to create graphs for different groups of my dataset. Range of groups is different (varies from few tens to tens of thousands). Here my problem arises. I would like to have more precise ticks on y-axis, but they are set automatically and for example if there is group with 20000 rows, there are only four ticks on y-axis - 0, 5000, 10000 and 15000. How can I set more ticks, and how can I add tick for 20000 if there is less than 20000 rows in group (e.g. if there is 19980 rows, last ticks is 15000).
I am enclosing screen of one of my graphs, where one of groups has almost 600 rows, but when you take a look on ticks on y-axis, the last one is 400.
for i in range(0, len(MDCstart)):
mdc_22 = d_spolu[d_spolu.drg_22.str.startswith(MDCstart[i])]
print(f'MDCka je {i}, tzn. {MDCstart[i]}')
plot = (p9.ggplot(data=mdc_22,
mapping=p9.aes(x='factor(drg_22)'))
+ p9.geom_bar(position=p9.position_dodge2(preserve='single'), fill='orange')
+ p9.theme_bw()
+ p9.theme(axis_text_x=p9.element_text(angle=90))
+ p9.labs(x='DRG skupina', y='Pocet')
+ p9.theme(figure_size=(20, 5))
+ p9.labels.ggtitle(title=f'ADRG zacinajuce na {MDCstart[i]}')
# + p9.scale_y_continuous(limits=(0, 15000, 500))
)
print(plot)
As you can see, I tried using scale_y_continuous
with limits 0 and 15000 with a step of 500, but it sets the limits, and shows just the values between 0 and 500 in my graphs.
My intention is to find out the way to automatically set "good ticks" - so lets say I want to see 8 ticks on each graph on y-axis with suitable values. Is this possible in some not too much complicated way?
All of these are just "cosmetics" to my graphs, but I would like to know how to make them look the way I want :)