DanGoodrick DanGoodrick - 1 year ago 149
Python Question

Is there a way to turn off Scientific Notation for Mpld3 plugins

I want to use mpld3's MousePosition plugin to display the pixel location of my cursor. This works great, but I can't figure out how to turn off scientific notation in the plugin. Pixels > 1000 are displayed in scientific notation.

My code:

import mpld3
from mpld3 import plugins
fig, ax = plt.subplots()
cross = cv2.imread("cross.png", 0)
img = cv2.imread('frame_400.png', 0)
res = cv2.matchTemplate(img[2500:, :1200], cv2.resize(cross, (0,0), fx = 2, fy = 2), 3)
pylab.rcParams['figure.figsize'] = (10.0, 10.0)
imshow(res, origin='lower', cmap = cm.gray)
plugins.connect(fig, plugins.MousePosition(fontsize=14))

Answer Source

There is a property for display format

plugins.connect(fig, plugins.MousePosition(fmt="f")) 

This will display the mouse position in integer format (a float with no decimal units of precision). fmt=".1f" will display the location with 1 decimal place of precision.

Ref: https://mpld3.github.io/_modules/mpld3/plugins.html

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download