Last active
December 21, 2018 19:42
-
-
Save MikeTheWatchGuy/fd79baad627ae879bb74437427ad4ff0 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import PySimpleGUI as sg | |
import random | |
BAR_WIDTH = 50 | |
BAR_SPACING = 75 | |
EDGE_OFFSET = 3 | |
GRAPH_SIZE = (500,500) | |
DATA_SIZE = (500,500) | |
graph = sg.Graph(GRAPH_SIZE, (0, 0), DATA_SIZE) | |
layout = [[sg.Text('Bar graphs using PySimpleGUI')], | |
[graph], | |
[sg.Button('OK')]] | |
window = sg.Window('Window Title').Layout(layout) | |
while True: | |
event, values = window.Read() | |
if event is None: | |
break | |
graph.Erase() | |
for i in range(7): | |
graph_value = random.randint(0, 400) | |
graph.DrawRectangle(top_left=(i * BAR_SPACING + EDGE_OFFSET, graph_value), | |
bottom_right=(i * BAR_SPACING + EDGE_OFFSET + BAR_WIDTH, 0), fill_color='blue') | |
graph.DrawText(text=graph_value, location=(i*BAR_SPACING+EDGE_OFFSET+25, graph_value+10)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
The coordinate system is (0,0) is the bottom left corner. (500,500) is the top right. This is identical to the positive portion of a 4-quadrant graph. You can just as easy define a traditional graph with 0,0 being in the center of the diagram. For that you use (-250,-250) for bottom left and (250,250) for top right.
Here's the image produced when using a 500x500 size.