1

I am trying to set Interval Unit (for interval between labels) of chart using openpyxl. This option is set to 'Automatic' by default. Image shows how we can set the option manually in Excel. Image Link

I found this option in XlsxWriter:

chart.set_x_axis({'interval_unit': 5})

but could not find the option in openpyxl. Please help.

Parth Karia
  • 265
  • 1
  • 4
  • 11

1 Answers1

4

For bar and column charts in openpyxl the axis labeling individual data is of type openpyxl.chart.axis.TextAxis. TextAxis features a property named tickLblSkip which defines what you are looking for. You can set a labeling interval of 5 as follows:

from openpyxl.chart import BarChart

chart = BarChart
chart.x_axis.tickLblSkip = 5
Friedemann Hahn
  • 290
  • 2
  • 10
  • If your problem is solved, please accept the answer. – Friedemann Hahn May 09 '17 at 07:25
  • My chart is automatically generating a Y axis scale of 0, .5, 1, 1.5 etc. This is supposed to create a scale of 0, 5, 10, 15 etc. Am I understanding that correctly? I cannot get it to work – Chris Macaluso Dec 12 '19 at 12:04
  • The answer given here only applies to charts whose axes are of type `TextAxis`. It seems like you are rather trying to format a regular numeric axis? If so I would recommend you ask a new question and in best case also provide a minimal working example to demonstrate what you want to achieve. – Friedemann Hahn Dec 13 '19 at 13:47
  • I think you're correct, although I haven't heard of `TestAxis` vs a regular numeric axis. I did post the question yesterday but no one has a suggestion yet. It can be found here: https://stackoverflow.com/questions/59304386/openpyxl-increment-of-x-and-y-axis-ticks – Chris Macaluso Dec 13 '19 at 14:03