How do you import an xkcd fig to html using mpld3

218 views Asked by At

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.

1

There are 1 answers

1
Abraham D Flaxman On BEST ANSWER

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.