python-pptx access category axis elements "tickLblSkip" & "tickMarkSkip"

1.3k views Asked by At

I used pptx to create a line chart with a lot of indices. I would like to tell ppt to label tick marks every 144 indices using the XML element shown here: http://python-pptx.readthedocs.io/en/latest/dev/analysis/cht-axes.html#related-schema-definitions

Unfortunately I can't figure out how to call that element and can't find any examples to help. Is anyone able to help?

thanks, Jerry

1

There are 1 answers

2
scanny On BEST ANSWER

Tick-mark spacing on a value axis (the "Y" axis, generally the vertical axis) is controlled by ValueAxis.major_unit and ValueAxis.minor_unit: http://python-pptx.readthedocs.io/en/latest/api/chart.html#value-axes

A value axis has both minor and major tick marks. For example, you might have a long tick mark every five units and a short tick-mark every one unit. These can be controlled separately, including causing them not to appear.

In your case, I think you want something like:

from pptx.enum.chart import XL_TICK_MARK

value_axis = chart.value_axis
value_axis.major_tick_mark = XL_TICK_MARK.OUTSIDE
value_axis.minor_tick_mark = XL_TICK_MARK.NONE
value_axis.major_unit = 144

Note that an XY (Scatter) chart has a value axis for both the X and Y dimensions; therefore tick marks can be controlled separately for each axis.

A category axis has discrete values (category labels), so tick mark units don't apply.