seaborn violin plots to_bokeh ValueError: invalid literal for int() with base 10: '4.59375'

hi all,

I just wanted to document a solved error which took me a while to get to the root of:

Problem situation: I wanted to to integrate seaborn violinplots in a bokeh server app, where other plots were already present (bokeh 0.12.5, seaborn 0.7.1, mpl 2.0.1).
The problem can be reproduced with the seaborn example

sns.set(style="whitegrid", palette="pastel", color_codes=True)

import matplotlib.pyplot as plt
import seaborn as sns
from bokeh import mpl
from bokeh.io import show

tips = sns.load_dataset("tips")
plt.figure()
ax = sns.violinplot(x="day", y="total_bill", hue="sex", data=tips, split=True,
               inner="quart", palette={"Male": "b", "Female": "y"})
bk = mpl.to_bokeh()
show(bk)

``

which (for me) results in
ValueError: invalid literal for int() with base 10: ‘4.59375’

``

with the stack trace

···

ValueError Traceback (most recent call last)
in ()
8 ax = sns.violinplot(x=“day”, y=“total_bill”, hue=“sex”, data=tips, split=True,
9 inner=“quart”, palette={“Male”: “b”, “Female”: “y”})
—> 10 bk = mpl.to_bokeh()

/home/chris/anaconda3/envs/avl/lib/python3.5/site-packages/bokeh/core/compat/mpl.py in to_bokeh(fig, tools, use_pandas, xkcd)
55 exporter = BokehExporter(renderer)
56
—> 57 exporter.run(fig)
58
59 return renderer.fig

/home/chris/anaconda3/envs/avl/lib/python3.5/site-packages/bokeh/core/compat/mplexporter/exporter.py in run(self, fig)
49 import matplotlib.pyplot as plt
50 plt.close(fig)
—> 51 self.crawl_fig(fig)
52
53 @staticmethod

/home/chris/anaconda3/envs/avl/lib/python3.5/site-packages/bokeh/core/compat/mplexporter/exporter.py in crawl_fig(self, fig)
116 props=utils.get_figure_properties(fig)):
117 for ax in fig.axes:
–> 118 self.crawl_ax(ax)
119
120 def crawl_ax(self, ax):

/home/chris/anaconda3/envs/avl/lib/python3.5/site-packages/bokeh/core/compat/mplexporter/exporter.py in crawl_ax(self, ax)
123 props=utils.get_axes_properties(ax)):
124 for line in ax.lines:
–> 125 self.draw_line(ax, line)
126 for text in ax.texts:
127 self.draw_text(ax, text)

/home/chris/anaconda3/envs/avl/lib/python3.5/site-packages/bokeh/core/compat/mplexporter/exporter.py in draw_line(self, ax, line, force_trans)
196 markerstyle=markerstyle,
197 label=label,
–> 198 mplobj=line)
199
200 def draw_text(self, ax, text, force_trans=None, text_type=None):

/home/chris/anaconda3/envs/avl/lib/python3.5/site-packages/bokeh/core/compat/mplexporter/renderers/base.py in draw_marked_line(self, data, coordinates, linestyle, markerstyle, label, mplobj)
153 “”"
154 if linestyle is not None:
–> 155 self.draw_line(data, coordinates, linestyle, label, mplobj)
156 if markerstyle is not None:
157 self.draw_markers(data, coordinates, markerstyle, label, mplobj)

/home/chris/anaconda3/envs/avl/lib/python3.5/site-packages/bokeh/core/compat/bokeh_renderer.py in draw_line(self, data, coordinates, style, label, mplobj)
199 line.line_width = style[‘linewidth’]
200 line.line_alpha = style[‘alpha’]
–> 201 line.line_dash = if style[‘dasharray’] is “none” else [int(i) for i in style[‘dasharray’].split(",")] # str2list(int)
202 # line.line_join = line2d.get_solid_joinstyle() # not in mplexporter
203 # line.line_cap = cap_style_map[line2d.get_solid_capstyle()] # not in mplexporter

/home/chris/anaconda3/envs/avl/lib/python3.5/site-packages/bokeh/core/compat/bokeh_renderer.py in (.0)
199 line.line_width = style[‘linewidth’]
200 line.line_alpha = style[‘alpha’]
–> 201 line.line_dash = if style[‘dasharray’] is “none” else [int(i) for i in style[‘dasharray’].split(",")] # str2list(int)
202 # line.line_join = line2d.get_solid_joinstyle() # not in mplexporter
203 # line.line_cap = cap_style_map[line2d.get_solid_capstyle()] # not in mplexporter

``

I could pinpoint it to the linestyle used. after iterating through all lines in ax and setting them to a different linestyle, the conversion worked.

import matplotlib.pyplot as plt
import seaborn as sns
from bokeh import mpl
from bokeh.io import show

tips = sns.load_dataset("tips")
plt.figure()
sns.set(style="whitegrid", palette="pastel", color_codes=True)
ax = sns.violinplot(x="day", y="total_bill", hue="sex", data=tips, split=True,
               inner="quart", palette={"Male": "b", "Female": "y"})
for line in ax.lines:
    line.set_linestyle('-')
bk = mpl.to_bokeh()
show(bk)

``

Hi,

Just as a friendly reminder, Bokeh's MPL compat has been deprecated and will be removed entirely on the release of Bokeh 1.0. If/when MPL offers a robust serialization option we can possibly revisit MPL compat in a new separate project. But the current implementation has become unmaintainable (it relies on a third party library that has been abandoned and that also uses private MPL APIs that are outdated).

Thanks,

Bryan

···

On May 8, 2017, at 15:26, Christopher Kittel <[email protected]> wrote:

hi all,

I just wanted to document a solved error which took me a while to get to the root of:

Problem situation: I wanted to to integrate seaborn violinplots in a bokeh server app, where other plots were already present (bokeh 0.12.5, seaborn 0.7.1, mpl 2.0.1).
The problem can be reproduced with the seaborn example
import matplotlib.pyplot as plt
import seaborn as sns
from bokeh import mpl
from bokeh.io import show

tips = sns.load_dataset("tips")
plt.figure()
sns.set(style="whitegrid", palette="pastel", color_codes=True)
ax = sns.violinplot(x="day", y="total_bill", hue="sex", data=tips, split=True,
               inner="quart", palette={"Male": "b", "Female": "y"})
bk = mpl.to_bokeh()
show(bk)

which (for me) results in
ValueError: invalid literal for int() with base 10: '4.59375'

with the stack trace
---------------------------------------------------------------------------
ValueError Traceback (most recent call last)
<ipython-input-1-a3d09ac65068> in <module>()
      8 ax = sns.violinplot(x="day", y="total_bill", hue="sex", data=tips, split=True,
      9 inner="quart", palette={"Male": "b", "Female": "y"})
---> 10 bk = mpl.to_bokeh()

/home/chris/anaconda3/envs/avl/lib/python3.5/site-packages/bokeh/core/compat/mpl.py in to_bokeh(fig, tools, use_pandas, xkcd)
     55 exporter = BokehExporter(renderer)
     56
---> 57 exporter.run(fig)
     58
     59 return renderer.fig

/home/chris/anaconda3/envs/avl/lib/python3.5/site-packages/bokeh/core/compat/mplexporter/exporter.py in run(self, fig)
     49 import matplotlib.pyplot as plt
     50 plt.close(fig)
---> 51 self.crawl_fig(fig)
     52
     53 @staticmethod

/home/chris/anaconda3/envs/avl/lib/python3.5/site-packages/bokeh/core/compat/mplexporter/exporter.py in crawl_fig(self, fig)
    116 props=utils.get_figure_properties(fig)):
    117 for ax in fig.axes:
--> 118 self.crawl_ax(ax)
    119
    120 def crawl_ax(self, ax):

/home/chris/anaconda3/envs/avl/lib/python3.5/site-packages/bokeh/core/compat/mplexporter/exporter.py in crawl_ax(self, ax)
    123 props=utils.get_axes_properties(ax)):
    124 for line in ax.lines:
--> 125 self.draw_line(ax, line)
    126 for text in ax.texts:
    127 self.draw_text(ax, text)

/home/chris/anaconda3/envs/avl/lib/python3.5/site-packages/bokeh/core/compat/mplexporter/exporter.py in draw_line(self, ax, line, force_trans)
    196 markerstyle=markerstyle,
    197 label=label,
--> 198 mplobj=line)
    199
    200 def draw_text(self, ax, text, force_trans=None, text_type=None):

/home/chris/anaconda3/envs/avl/lib/python3.5/site-packages/bokeh/core/compat/mplexporter/renderers/base.py in draw_marked_line(self, data, coordinates, linestyle, markerstyle, label, mplobj)
    153 """
    154 if linestyle is not None:
--> 155 self.draw_line(data, coordinates, linestyle, label, mplobj)
    156 if markerstyle is not None:
    157 self.draw_markers(data, coordinates, markerstyle, label, mplobj)

/home/chris/anaconda3/envs/avl/lib/python3.5/site-packages/bokeh/core/compat/bokeh_renderer.py in draw_line(self, data, coordinates, style, label, mplobj)
    199 line.line_width = style['linewidth']
    200 line.line_alpha = style['alpha']
--> 201 line.line_dash = if style['dasharray'] is "none" else [int(i) for i in style['dasharray'].split(",")] # str2list(int)
    202 # line.line_join = line2d.get_solid_joinstyle() # not in mplexporter
    203 # line.line_cap = cap_style_map[line2d.get_solid_capstyle()] # not in mplexporter

/home/chris/anaconda3/envs/avl/lib/python3.5/site-packages/bokeh/core/compat/bokeh_renderer.py in <listcomp>(.0)
    199 line.line_width = style['linewidth']
    200 line.line_alpha = style['alpha']
--> 201 line.line_dash = if style['dasharray'] is "none" else [int(i) for i in style['dasharray'].split(",")] # str2list(int)
    202 # line.line_join = line2d.get_solid_joinstyle() # not in mplexporter
    203 # line.line_cap = cap_style_map[line2d.get_solid_capstyle()] # not in mplexporter

I could pinpoint it to the linestyle used. after iterating through all lines in ax and setting them to a different linestyle, the conversion worked.

import matplotlib.pyplot as plt
import seaborn as sns
from bokeh import mpl
from bokeh.io import show

tips = sns.load_dataset("tips")
plt.figure()
sns.set(style="whitegrid", palette="pastel", color_codes=True)
ax = sns.violinplot(x="day", y="total_bill", hue="sex", data=tips, split=True,
               inner="quart", palette={"Male": "b", "Female": "y"})
for line in ax.lines:
    line.set_linestyle('-')
bk = mpl.to_bokeh()
show(bk)

--
You received this message because you are subscribed to the Google Groups "Bokeh Discussion - Public" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [email protected].
To post to this group, send email to [email protected].
To view this discussion on the web visit https://groups.google.com/a/continuum.io/d/msgid/bokeh/a6f62daf-9c35-4a8d-9ef8-61751f84564b%40continuum.io.
For more options, visit https://groups.google.com/a/continuum.io/d/optout.