Skip to content
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

Unicode symbols in jupyter notebook plots (plotly3) #1289

Closed
Gorfar opened this issue Nov 29, 2018 · 1 comment
Closed

Unicode symbols in jupyter notebook plots (plotly3) #1289

Gorfar opened this issue Nov 29, 2018 · 1 comment
Labels
bug something broken
Milestone

Comments

@Gorfar
Copy link

Gorfar commented Nov 29, 2018

Hello!

I am using plotly3 for plots in Jupyter notebook. If I want to add an unicode symbol in an axis title it doesn't work, however, it worked in the plotly2.

In the following code

import plotly.graph_objs as go
layout=go.Layout()
layout.xaxis.title = u"μ"
fig = go.FigureWidget(layout=layout)
fig

I get the error " 'ascii' codec can't encode character u'\u03bc' in position 0: ordinal not in range(128)"

I use anaconda environment on OpenSuse Leap 42.3
conda=4.5.11
ipykernel=4.9.0
ipython=5.8.0
plotly=3.4.1
plotly-orca=1.1.1
python=2.7.15

@jonmmease
Copy link
Contributor

Thanks for taking the time to report this @Gorfar, this looks like a problem on Python 2.

On Python 3.6:

import plotly.graph_objs as go
layout=go.Layout()
layout.xaxis.title = u"μ"
fig = go.FigureWidget(layout=layout)
fig

newplot 2

On Python 2.7:

---------------------------------------------------------------------------
UnicodeEncodeError                        Traceback (most recent call last)
<ipython-input-1-e0358ce99901> in <module>()
      1 import plotly.graph_objs as go
      2 layout=go.Layout()
----> 3 layout.xaxis.title = u"μ"
      4 fig = go.FigureWidget(layout=layout)
      5 fig

/Users/jmmease/Plotly/repos/plotly.py/plotly/basedatatypes.py in __setattr__(self, prop, value)
   2836                 prop in self._validators):
   2837             # Let known properties and private properties through
-> 2838             super(BasePlotlyType, self).__setattr__(prop, value)
   2839         else:
   2840             # Raise error on unknown public properties

/Users/jmmease/Plotly/repos/plotly.py/plotly/graph_objs/layout/_xaxis.py in title(self, val)
   1798     @title.setter
   1799     def title(self, val):
-> 1800         self['title'] = val
   1801 
   1802     # titlefont

/Users/jmmease/Plotly/repos/plotly.py/plotly/basedatatypes.py in __setitem__(self, prop, value)
   2808             # ### Handle simple property ###
   2809             else:
-> 2810                 self._set_prop(prop, value)
   2811 
   2812         # Handle non-scalar case

/Users/jmmease/Plotly/repos/plotly.py/plotly/basedatatypes.py in _set_prop(self, prop, val)
   3044                 return
   3045             else:
-> 3046                 raise err
   3047 
   3048         # val is None

UnicodeEncodeError: 'ascii' codec can't encode character u'\u03bc' in position 0: ordinal not in range(128)

There is some exception handling obscuring the strack trace, but I think the issue is with the use of str in the StringValidator class.

# Convert value to a string
v = str(v)

# Convert all elements other than None to strings
# Leave None as is, Plotly.js will decide how to handle
# these null values.
v = [str(e) if e is not None else None for e in v]

We should only really do these str conversions if the input value isn't alreadyof type str or unicode.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug something broken
Projects
None yet
Development

No branches or pull requests

2 participants