Sunday, 29 December 2019

django mpld3 point tooltip

hover on point, tooltip with x, y position is displayed

from django.http import  HttpResponse
import matplotlib.pyplot as plt
from mpld3 import plugins, fig_to_html, save_html

def index(request):
    fig, ax = plt.subplots()
    points = ax.plot(range(10), 'o')
    plugins.connect(fig, plugins.PointLabelTooltip(points[0]))

    save_html(fig, 'fig.html')

    g = fig_to_html(fig)
    return HttpResponse(g)
figure is also saved as html file

double click on saved file, browser will open it up

reference:

No comments:

Post a Comment