New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Is it possible to set the interval between labels on the x axis ? #69

Closed
tooh opened this Issue Nov 23, 2013 · 5 comments

Comments

2 participants
@tooh

tooh commented Nov 23, 2013

I have x axis with dates and I only want to show intervals of 5 (otherwise the x-axis is to crowded because there is no room for all dates to be displayed properly.

In Excel I have found the option :
Scale-> Interval between labels

This gives the desired effect.

Is this supported or can this be achieved otherwise ?

@ghost ghost assigned jmcnamara Nov 23, 2013

@jmcnamara

This comment has been minimized.

Show comment
Hide comment
@jmcnamara

jmcnamara Nov 23, 2013

Owner

Hi Peter,

That isn't currently possible but I'll put it on the shorter TODO list. There are a lot of chart features and sub-features and I'm trying to cover as many as possible. :-)

In the meantime you may be able to workaround the issue by rotating the dates in the x-axis (sometimes Excel does this automatically). Here is an example:

from datetime import date
import xlsxwriter

workbook = xlsxwriter.Workbook('chart.xlsx')

date_format = workbook.add_format({'num_format': 'yyyy-mm-dd'})

worksheet = workbook.add_worksheet()
chart = workbook.add_chart({'type': 'line'})

dates = [date(2013, 11, 1), 
         date(2013, 11, 2), 
         date(2013, 11, 3), 
         date(2013, 11, 4), 
         date(2013, 11, 5)]

values = [6, 9, 5, 12, 5]

worksheet.set_column('A:A', 12);
worksheet.write_column('A1', dates, date_format)
worksheet.write_column('B1', values)

chart.add_series({
   'categories': '=Sheet1!$A$1:$A$5',
   'values':     '=Sheet1!$B$1:$B$5',
})

chart.set_x_axis({'num_font': {'rotation': -45}})

worksheet.insert_chart('E9', chart)

workbook.close()

Output:

screenshot

Owner

jmcnamara commented Nov 23, 2013

Hi Peter,

That isn't currently possible but I'll put it on the shorter TODO list. There are a lot of chart features and sub-features and I'm trying to cover as many as possible. :-)

In the meantime you may be able to workaround the issue by rotating the dates in the x-axis (sometimes Excel does this automatically). Here is an example:

from datetime import date
import xlsxwriter

workbook = xlsxwriter.Workbook('chart.xlsx')

date_format = workbook.add_format({'num_format': 'yyyy-mm-dd'})

worksheet = workbook.add_worksheet()
chart = workbook.add_chart({'type': 'line'})

dates = [date(2013, 11, 1), 
         date(2013, 11, 2), 
         date(2013, 11, 3), 
         date(2013, 11, 4), 
         date(2013, 11, 5)]

values = [6, 9, 5, 12, 5]

worksheet.set_column('A:A', 12);
worksheet.write_column('A1', dates, date_format)
worksheet.write_column('B1', values)

chart.add_series({
   'categories': '=Sheet1!$A$1:$A$5',
   'values':     '=Sheet1!$B$1:$B$5',
})

chart.set_x_axis({'num_font': {'rotation': -45}})

worksheet.insert_chart('E9', chart)

workbook.close()

Output:

screenshot

@tooh

This comment has been minimized.

Show comment
Hide comment
@tooh

tooh Nov 23, 2013

Hi John,

Thanks for your extensive answer. I applied this workaround and it works OK. Look forward to the new release.

Peter

tooh commented Nov 23, 2013

Hi John,

Thanks for your extensive answer. I applied this workaround and it works OK. Look forward to the new release.

Peter

jmcnamara added a commit that referenced this issue Dec 1, 2013

@jmcnamara

This comment has been minimized.

Show comment
Hide comment
@jmcnamara

jmcnamara Dec 1, 2013

Owner

I've pushed an initial fix for this to the master branch.

You can now specify an interval_unit for category axes:

chart.set_x_axis({'interval_unit': 2, ...})

I need to add it to the documentation before release but if you wish to try it out before that let me know if you encounter any issues.

Owner

jmcnamara commented Dec 1, 2013

I've pushed an initial fix for this to the master branch.

You can now specify an interval_unit for category axes:

chart.set_x_axis({'interval_unit': 2, ...})

I need to add it to the documentation before release but if you wish to try it out before that let me know if you encounter any issues.

@tooh

This comment has been minimized.

Show comment
Hide comment
@tooh

tooh Dec 2, 2013

I tried it and it works OK. Thx for the support.

2013-12-02 at 13 03

tooh commented Dec 2, 2013

I tried it and it works OK. Thx for the support.

2013-12-02 at 13 03

@jmcnamara

This comment has been minimized.

Show comment
Hide comment
@jmcnamara

jmcnamara Dec 2, 2013

Owner

Fixed in version 0.5.1 which has been uploaded to PyPI.

Thanks for the suggestion.

Owner

jmcnamara commented Dec 2, 2013

Fixed in version 0.5.1 which has been uploaded to PyPI.

Thanks for the suggestion.

@jmcnamara jmcnamara closed this Dec 2, 2013

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment