0

I'm having a bit of trouble with the following run in an ipython notebook on mac osx with python 3.3:

import mpld3
from mpld3 import plugins
mpld3.enable_notebook()

fig, ax = plt.subplots()
points = plt.scatter([0,3,5, 9], [2,4,6, 8])
labels= ['a', 'b', 'c']
#ax.xaxis.set_ticks([2,4])
tooltip = plugins.PointHTMLTooltip(points, labels,
                                   voffset=10, hoffset=10)
plugins.connect(fig, tooltip)
mpld3.display()

Works great. However, if I uncomment out:

ax.xaxis.set_ticks([2,4])

It crashes with the error: TypeError: 2 is not JSON serializable

Is this a bug? Is there a work around?

Thanks!

SHIVANG RANA
  • 384
  • 6
  • 25
dylkot
  • 2,275
  • 2
  • 20
  • 24
  • Apparently, the function wants a json object, you give it a list, try to pass json.dumps([2,4]) as parameter. – lqhcpsgbl Jan 27 '15 at 06:33
  • 1
    changing it to: ax.xaxis.set_ticks(json.dumps([2,4]) ) crashes with the error message: TypeError: unorderable types: numpy.ndarray() < str() – dylkot Jan 27 '15 at 06:47

1 Answers1

0

This is a bug, thanks for identifying it. The work around is to use plt.xticks and provide labels for the ticks explicitly:

plt.xticks([2,4], [2,4])
Abraham D Flaxman
  • 2,969
  • 21
  • 39
  • Thanks for pointing this out! It will definitely help me out in something I'm trying out. I would love to try to improve this aspect of mpld3 at some point. – dylkot Jan 28 '15 at 05:07