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

Scatter 'marker': {'type': 'diamond'} gives an error #62

Closed
Norfeldt opened this Issue Nov 8, 2013 · 9 comments

Comments

2 participants
@Norfeldt

Norfeldt commented Nov 8, 2013

I have the following code:

d = 4
chart.add_series({
    'name': "Key points",
    'categories':  '=Sheet1!$C$1:$C$%i' % (d+1),
    'values': '=Sheet1!$D$1:$D$%i' % (d+1),
    'data_labels': {'category': True, 'position': 'top'},
    'line':   {'none': True},
    'marker': {'type': 'diamond'},
    })

But running it gives an error

  File "location/to/the/python/script", line 70, in <module>
    workbook.close()
  File "C:\Python27\lib\site-packages\xlsxwriter\workbook.py", line 240, in clos
e
    self._store_workbook()
  File "C:\Python27\lib\site-packages\xlsxwriter\workbook.py", line 400, in _sto
re_workbook
    packager._create_package()
  File "C:\Python27\lib\site-packages\xlsxwriter\packager.py", line 122, in _cre
ate_package
    self._write_chart_files()
  File "C:\Python27\lib\site-packages\xlsxwriter\packager.py", line 205, in _wri
te_chart_files
    chart._assemble_xml_file()
  File "C:\Python27\lib\site-packages\xlsxwriter\chart.py", line 531, in _assemb
le_xml_file
    self._write_chart()
  File "C:\Python27\lib\site-packages\xlsxwriter\chart.py", line 1183, in _write
_chart
    self._write_plot_area()
  File "C:\Python27\lib\site-packages\xlsxwriter\chart_scatter.py", line 173, in
 _write_plot_area
    self._write_chart_type({'primary_axes': 1})
  File "C:\Python27\lib\site-packages\xlsxwriter\chart_scatter.py", line 53, in
_write_chart_type
    self._write_scatter_chart(args)
  File "C:\Python27\lib\site-packages\xlsxwriter\chart_scatter.py", line 92, in
_write_scatter_chart
    self._modify_series_formatting()
  File "C:\Python27\lib\site-packages\xlsxwriter\chart_scatter.py", line 277, in
 _modify_series_formatting
    if not series.get('marker') or not series['marker']['defined']:
KeyError: 'defined'
>>>

Running it without the 'marker' works just fine.

My xlsxwriter version is 0.4.6

@ghost ghost assigned jmcnamara Nov 8, 2013

@jmcnamara

This comment has been minimized.

Show comment
Hide comment
@jmcnamara

jmcnamara Nov 8, 2013

Owner

Hi Lasse,

That looks like an issue that was fixed in a recent release. Are you sure you are on 0.4.6:

python -c "import xlsxwriter; print(xlsxwriter.__version__)"
0.4.6

I don't see the issue when running the following sample program:

import xlsxwriter

workbook = xlsxwriter.Workbook('chart_scatter.xlsx')
worksheet = workbook.add_worksheet()
bold = workbook.add_format({'bold': 1})

# Add the worksheet data that the charts will refer to.
headings = ['Number', 'Batch 1', 'Batch 2']
data = [
    [2, 3, 4, 5, 6, 7],
    [10, 40, 50, 20, 10, 50],
    [30, 60, 70, 50, 40, 30],
]

worksheet.write_row('A1', headings, bold)
worksheet.write_column('A2', data[0])
worksheet.write_column('B2', data[1])
worksheet.write_column('C2', data[2])

# Create a new scatter chart.
chart1 = workbook.add_chart({'type': 'scatter'})

# Configure the first series.
chart1.add_series({
    'name': '=Sheet1!$B$1',
    'categories': '=Sheet1!$A$2:$A$7',
    'values': '=Sheet1!$B$2:$B$7',
    'marker': {'type': 'diamond'},
})

# Insert the chart into the worksheet (with an offset).
worksheet.insert_chart('E2', chart1)

workbook.close()

If there is an issue can you modify the above program to demonstrate it.

John

Owner

jmcnamara commented Nov 8, 2013

Hi Lasse,

That looks like an issue that was fixed in a recent release. Are you sure you are on 0.4.6:

python -c "import xlsxwriter; print(xlsxwriter.__version__)"
0.4.6

I don't see the issue when running the following sample program:

import xlsxwriter

workbook = xlsxwriter.Workbook('chart_scatter.xlsx')
worksheet = workbook.add_worksheet()
bold = workbook.add_format({'bold': 1})

# Add the worksheet data that the charts will refer to.
headings = ['Number', 'Batch 1', 'Batch 2']
data = [
    [2, 3, 4, 5, 6, 7],
    [10, 40, 50, 20, 10, 50],
    [30, 60, 70, 50, 40, 30],
]

worksheet.write_row('A1', headings, bold)
worksheet.write_column('A2', data[0])
worksheet.write_column('B2', data[1])
worksheet.write_column('C2', data[2])

# Create a new scatter chart.
chart1 = workbook.add_chart({'type': 'scatter'})

# Configure the first series.
chart1.add_series({
    'name': '=Sheet1!$B$1',
    'categories': '=Sheet1!$A$2:$A$7',
    'values': '=Sheet1!$B$2:$B$7',
    'marker': {'type': 'diamond'},
})

# Insert the chart into the worksheet (with an offset).
worksheet.insert_chart('E2', chart1)

workbook.close()

If there is an issue can you modify the above program to demonstrate it.

John

@jmcnamara

This comment has been minimized.

Show comment
Hide comment
@jmcnamara

jmcnamara Nov 8, 2013

Owner

Possibly you are using the straight subtype:

chart1 = workbook.add_chart({'type': 'scatter', 'subtype': 'straight'})

In that case I see the issue.

Try the straight_with_markers subtype as a workaround while I fix this issue.

Owner

jmcnamara commented Nov 8, 2013

Possibly you are using the straight subtype:

chart1 = workbook.add_chart({'type': 'scatter', 'subtype': 'straight'})

In that case I see the issue.

Try the straight_with_markers subtype as a workaround while I fix this issue.

@jmcnamara

This comment has been minimized.

Show comment
Hide comment
@jmcnamara

jmcnamara Nov 8, 2013

Owner

I have a fix for this now that will prevent the error and stacktrace. I'll push it once I do a bit more testing.

Owner

jmcnamara commented Nov 8, 2013

I have a fix for this now that will prevent the error and stacktrace. I'll push it once I do a bit more testing.

@jmcnamara jmcnamara closed this in 55f1cd5 Nov 8, 2013

@jmcnamara

This comment has been minimized.

Show comment
Hide comment
@jmcnamara

jmcnamara Nov 8, 2013

Owner

This commit fixes the warning but also allows you to add markers to non-marker scatter charts.

Owner

jmcnamara commented Nov 8, 2013

This commit fixes the warning but also allows you to add markers to non-marker scatter charts.

@Norfeldt

This comment has been minimized.

Show comment
Hide comment
@Norfeldt

Norfeldt Nov 9, 2013

Hi John,

Thank you very much for such a fast respond and bug fix.

(I was using the chart = workbook.add_chart({'type': 'scatter', 'subtype': 'smooth'}) and not smooth_with_markers)

BTW: Thank you very much for a great module!

Norfeldt commented Nov 9, 2013

Hi John,

Thank you very much for such a fast respond and bug fix.

(I was using the chart = workbook.add_chart({'type': 'scatter', 'subtype': 'smooth'}) and not smooth_with_markers)

BTW: Thank you very much for a great module!

@jmcnamara

This comment has been minimized.

Show comment
Hide comment
@jmcnamara

jmcnamara Nov 10, 2013

Owner

Fix uploaded to PyPI in version 0.4.7.

Owner

jmcnamara commented Nov 10, 2013

Fix uploaded to PyPI in version 0.4.7.

@Norfeldt

This comment has been minimized.

Show comment
Hide comment
@Norfeldt

Norfeldt Nov 10, 2013

Thank you for this!

I found that the marker star do not work (don't think that there is a star marker), but the plus does.
The plus is not listed in the type section for the markers in https://xlsxwriter.readthedocs.org/en/latest/working_with_charts.html

Norfeldt commented Nov 10, 2013

Thank you for this!

I found that the marker star do not work (don't think that there is a star marker), but the plus does.
The plus is not listed in the type section for the markers in https://xlsxwriter.readthedocs.org/en/latest/working_with_charts.html

@jmcnamara

This comment has been minimized.

Show comment
Hide comment
@jmcnamara

jmcnamara Nov 10, 2013

Owner

I found that the marker star do not work

That is a bug. Can you raise a new issue for it and I'll push a fix.

The plus is not listed in the type section for the markers in

There is a typo in the docs, it is on the same line as circle. I'll fix that too.

Owner

jmcnamara commented Nov 10, 2013

I found that the marker star do not work

That is a bug. Can you raise a new issue for it and I'll push a fix.

The plus is not listed in the type section for the markers in

There is a typo in the docs, it is on the same line as circle. I'll fix that too.

@jmcnamara

This comment has been minimized.

Show comment
Hide comment
@jmcnamara

jmcnamara Nov 10, 2013

Owner

I've already pushed a fix so there is no need to create an issue.

Owner

jmcnamara commented Nov 10, 2013

I've already pushed a fix so there is no need to create an issue.

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