import pyglet import math window = pyglet.window.Window() window.set_caption("Test graph") title = pyglet.text.Label('Test Graph', font_name='Arkhip', font_size=12, x=window.width//2, y=window.height//2, anchor_x='center', anchor_y='top') def round_sig(x, sig=2): return round(x, sig-int(math.floor(math.log10(abs(x))))-1) def drawgrid(xlines, ylines, xlimits, ylimits): for xpos in range(0, window.width, window.width/xlines): pyglet.graphics.draw(2, pyglet.gl.GL_LINES, ('v2i', (xpos, 0, xpos, window.height))) tagtext = str(round((xlimits[1]-xlimits[0])*(float(xpos)/window.width), 1)) tag = pyglet.text.Label(tagtext, font_name='Arkhip', font_size=10, x=xpos-2, y=0, anchor_x='right', anchor_y='bottom') tag.draw() for ypos in range(0, window.width, window.width/ylines): pyglet.graphics.draw(2, pyglet.gl.GL_LINES, ('v2i', (0, ypos, window.width, ypos))) tagtext = str(round((ylimits[1]-ylimits[0])*(float(ypos)/window.height), 1)) tag = pyglet.text.Label(tagtext, font_name='Arkhip', font_size=10, x=0, y=ypos-2, anchor_x='left', anchor_y='top') tag.draw() def plotline(xdata, ydata): pass xdata = [1, 2, 3, 4, 5, 6, 7, 7.4, 9, 10] ydata = [81, 86, 58, 20, 59, 3, -6, 4.8] @window.event def on_draw(): window.clear() drawgrid(10, 12, [min(xdata), max(xdata)], [min(ydata), max(ydata)]) pyglet.app.run()