Skip to content

Archive Trac docs matplotlib

madscatt edited this page Jun 20, 2026 · 1 revision

Docs Matplotlib

Legacy Trac archive page imported from docs_matplotlib. Source: https://genapp.rocks/wiki/wiki/docs_matplotlib. Review age, links, and examples before treating as current.

streaming matplot lib notes

doing

  • tmp/pythonlib/
    • genapp.py / starting library for genapp python
    • ga_webagg.py / plot example
  • port pool notes

todo

import numpy as np
import matplotlib

print matplotlib.rcParams
matplotlib.use('webagg')
import matplotlib.pyplot as plt
import matplotlib.animation as animation
def update_line(num, data, line):
    print "update_line"
    line.set_data(data[..., :num])
    return line,

def myplotshow():
    matplotlib.rcParams['webagg.open_in_browser'] = False
    matplotlib.rcParams['webagg.address'] = "0.0.0.0"
    matplotlib.rcParams['webagg.port'] = 8080
    plt.show()

print "create figure"
fig1 = plt.figure()

data = np.random.rand(2, 25)
l, = plt.plot([], [], 'r-')
plt.xlim(0, 1) 
plt.ylim(0, 1)
plt.xlabel('x')
plt.title('test')
line_ani = animation.FuncAnimation(fig1, update_line, 25, fargs=(data, l),
                                   interval=200, blit=True)
myplotshow();
  • alternative?

    • use genapp
    • genapp sets up servers as needed
    • provides python library for setup of tcp, updating plots
  • using mpl.use('webagg')

    • global port range in appconfig?
    • genapp type "matplotlib'
    • assign a port from global pool for each jobs mpl plots
    • php routines to assign ports
      • mongo'd globally with timestamp, job info
      • scanner daemon to "clean up" or simply report status
    • setup iframe in type frag with responsive css
    • tcp server required
    • python library
    • ga_keepalive( jsoninput )
    • ga_plot_show( jsoninput, id )
    • reattach
    • get saved plot info, restart simple show'r from pickles

issues


architecture

genapp integrated

  • basic test
    • iframe matplotlib element
    • genapp python caller
    • python side
      • returns uuid for figure, initializes the handler, runs a local server
      • sets up a webpage
    • genapp server daemon that knows about this and routes calls to the python side
      • multiplexd over regular ws?
    • e.g.
    • user's python is running the server
    • genapp handles getting it to the UI
    • reattachment issue
      • reattaching after the job has run would somehow need to restart the servers
      • perhaps a hook could be registered in the genapp python caller for the final plot at end?

as is

  • serves websocket and http(s) over single port

working

  • works in iframes, responsive example:
<html>
  <style>
  .iframe-container {
    overflow: hidden;
    padding-top: 56.25%;
    position: relative;
}

.iframe-container iframe {
    border: 0;
    height: 100%;
    left: 0;
    position: absolute;
    top: 0;
    width: 100%;
}

  </style>

  <body>
    Test for matplotlib embedded in iframe
  <body>
    <div class="iframe-container">
      <iframe frameBorder=0 src=http://129.114.104.249:8080>iframe tag text</iframe>
    </div>
</html>
  • needs Agg for no X, so before import or from matplotlib
import matplotlib as mpl
mpl.use('Agg')

Clone this wiki locally