scanny / python-pptx

Create Open XML PowerPoint documents in Python
MIT License
2.4k stars 519 forks source link

How to set the value axis line to hide? #927

Closed boloyz closed 10 months ago

boloyz commented 10 months ago

chart.value_axis.format.line.color.rgb = RGBColor(255,255,255) The value_axis line is white, when I run above code, but I want to set the value axis to hide,and I want to display the tick_labels in value_axis. how can do it?

scanny commented 10 months ago

Are you able to do that by hand in PowerPoint?

scanny commented 10 months ago

and have you tried Axis.visible = False?

boloyz commented 10 months ago

and have you tried Axis.visible = False?

Yes, I 've already tried,when I added Axis.visible = False , the value axis was not visible,but the value axis's tick_labels was not visable too, I want the value axis only display tick_labels, the line to be hidden. like these screenshots image image

scanny commented 10 months ago

There is separate ChartFormat object for the axis and the MajorGridlines aspects of the chart. It could be that setting the line format for the former to None or whatever the "no-line" value is would turn it off, have you tried that? If it turns all the lines off than maybe MajorGridlines.format.line can turn it back on for the gridlines.

At this point I would inspect the XML for a chart that looks the way you want and see how it compares with what you produce with python-pptx so far and then work out how to match them using some aspect of the API. I vaguely remember having done this at least once though.

boloyz commented 10 months ago

Thank you for your reply , I tried two tests,

  1. Set chart.value_axis.format is None , the value axis's line color is black , the line always visible, like this screenshot. 0b0d2fe0e85d86d5936c490ea6e8110
  2. Set chart.value_axis.major_gridlines.format is None, the value axis major gridlines color is black, the line always visible,too, like this screenshot. 8e300f6c3f2f49d4b8c9599c3afd3a2
  3. If I add chart.value_axis.has_major_gridlines = False, the value axis major gridlines is not visable. but chart.value_axis not have similar like this attribute set line is not visable.
scanny commented 10 months ago

If you look into ChartFormat here (which is what axis.format is: https://python-pptx.readthedocs.io/en/latest/api/dml.html#pptx.dml.chtfmt.ChartFormat you can see it has line and fill attributes.

You can try some things there, drilling down into format.line, like maybe format.line.width = 0 or format.line.fill = None and see if you can achieve what you're looking for.

Use the API docs to understand what you're working with and explore what capabilities are there. You don't have to rely on someone having done it before to give you a recipe :)

boloyz commented 10 months ago

Thank you for your patient guidance. I was negligent in checking the document. My problem has been solved