3

I am trying to import a matplotlib to html with xkcd theme. My code is as follows (no data,just a fig)

fig = plt.figure(facecolor = '#eee8d5')
#plt.matplotlib.rcdefaults()
with plt.xkcd():

     ax = fig.add_subplot(111)

     ax.set_axis_bgcolor('#eee8d5') #set_color('#fdf6e3')

     ax.title.set_color('#d33682') # Magenta

     ax.tick_params(axis='x', colors='#657b83')
     ax.tick_params(axis='y', colors='#657b83')


     ax.spines['bottom'].set_color('#657b83')
     ax.spines['left'].set_color('#657b83')
     ax.spines['right'].set_color('none')
     ax.spines['top'].set_color('none')

     ax.set_title('Title', fontsize = 18);
     html = mpld3.fig_to_html(fig)
     Html_file= open("CumPrctWordFrq.html","w")
     Html_file.write(html)
     Html_file.close()

So far so good -- everything renders correctly in the python notebook. However when I paste the html on a website (squarespace), the fig loses all the xkcd properties. Eventually I would like to make this interactive. The idea is eventually to produce a xkcd -> solarized -> interactive plot.

itay livni
  • 55
  • 1
  • 6
  • Actually this only works in the notebook because the inline backend is used to draw the figure and not mpld3. I fear the _xkcd_ style is not implemented in mpld3 yet. – Jakob Nov 23 '14 at 09:42
  • Thanks @Jakob - I suppose when [MEP25](https://github.com/matplotlib/matplotlib/wiki/MEP25) is resolved then passing plots from one plotting package to another (for additional functionality) will be trivial. More of a question than a statement. – itay livni Nov 23 '14 at 19:02
  • It did you find an alternative solution to `mpld3` to display the xckd style graphs? – Jeel Shah Dec 31 '14 at 21:00
  • No. In the end I just ended up a .png of the image from matplotlib – itay livni Jan 11 '15 at 17:23

1 Answers1

1

mpld3 does not yet support the plt.xkcd() mode. If this is something you want, you should creat an issue in the mpld3 issue tracker, and see if someone is inspired to work on it.

Abraham D Flaxman
  • 2,969
  • 21
  • 39