Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Python PPTX - How to set chart axis number format and range

I'm trying to accommodate a Bar Chart Y axis with a range from 0 to 1 with 1 decimal place like: 1.2 for tick labels:

I can set it to start at 0 with:

 Thisvalue_axis.minimum_scale = 0

And I can set the top value with:

 Thisvalue_axis.major_unit = 1

But the intermediate tick labels are not showing

here is my code:

Thisvalue_axis = ThisChart.value_axis
Thisvalue_axis.minimum_scale = 0
Thisvalue_axis.major_unit = 1
Thisvalue_axis.minor_tick_mark = XL_TICK_MARK.OUTSIDE
Thisvalue_axis.has_minor_gridlines = True

Is it possible to Make the values between 0 and 1 display and set the numberformat?

like image 534
Mattman85208 Avatar asked Aug 03 '26 09:08

Mattman85208


1 Answers

You should set the top value by using:

value_axis.maximum_scale = 1

And then set the major unit to 0.1 or 0.2 or whatever suits:

value_axis.major_unit = 0.1

This particular example would show 0.0, 0.1, 0.2, ... 1.0 as the tick mark labels.

Another look results from setting the major unit as 1 and setting the minor unit to 0.1 (or whatever you like). This would generally show a more prominent tick mark for the major unit and a less prominent one for the minor unit. Note however that tick labels only appear on the major tick marks.

The number format is set using the TickLabels object available on Axis.tick_labels:

value_axis.tick_labels.number_format = '0.0'
like image 101
scanny Avatar answered Aug 05 '26 21:08

scanny



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!