Okay..the output of a python program is shown into a Tkinter window..which opens separately. What I want to do is to embed this window within the browser. Here is the code:
import numpy as np
import matplotlib
import matplotlib.cbook as cbook
import matplotlib.image as image
import matplotlib.pyplot as plt
datafile = cbook.get_sample_data('logo2.png', asfileobj=False)
print 'loading', datafile
im = image.imread(datafile)
im[:,:,-1] = 0.5 # set the alpha channel
fig = plt.figure()
ax = fig.add_subplot(111)
ax.plot(np.random.rand(20), '-o', ms=20, lw=2, alpha=0.7, mfc='orange')
ax.grid()
fig.figimage(im, 10, 10)
plt.show()
Consider that all the variables are input parameters that are given from a browser form field. Please help!! :-)
Based on Joe Kington's answer to a similar question, the backend mplh5canvas is possibly what you are looking for. Adapting your example code to work with it,
import numpy as np
import matplotlib
import mplh5canvas
matplotlib.use('module://mplh5canvas.backend_h5canvas')
import matplotlib.cbook as cbook
import matplotlib.image as image
import matplotlib.pyplot as plt
fig = plt.figure()
ax = fig.add_subplot(111)
ax.plot(np.random.rand(20), '-o', ms=20, lw=2, alpha=0.7, mfc='orange')
ax.grid()
plt.show(open_plot=True)
It seems to work well with the kind of interactivity you are looking for, even allowing animation. Having said that, it doesn't support every browser, as described in it's installation wiki page. If it is acceptable to restrict use to Chrome, Safari or Opera (in this case with some configuration, check that page) then it should suit you well, though might need some experimentation as well.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With