Skip to content

Instantly share code, notes, and snippets.

@vigilantPotato
Created April 22, 2024 21:47
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save vigilantPotato/c340201eb2664e9e5e877ab63aefa5c5 to your computer and use it in GitHub Desktop.
Save vigilantPotato/c340201eb2664e9e5e877ab63aefa5c5 to your computer and use it in GitHub Desktop.
bar graph options
import ctypes
import tkinter
import matplotlib.pyplot as plt
import numpy as np
from matplotlib.backends.backend_tkagg import FigureCanvasTkAgg, NavigationToolbar2Tk
if __name__ == "__main__":
ctypes.windll.shcore.SetProcessDpiAwareness(1)
root = tkinter.Tk()
#graph data(dictionary)
x = np.arange(5)
y = [1, 5, 2, 9, 10]
data = {"x":x, "y":y}
label = ["a", "b", "c", "d", "e"]
fill_color = ["r", "g", "c", "b", "y"]
edge_color = ["g", "c", "b", "y", "r"]
hatch = ["/", "|", "-", "+", "o"]
error_y = [0.3, 0.4, 0.5, 0.6, 0.7]
#create graph objects
fig, ax = plt.subplots()
#show graph
ax.bar("x", "y", data=data,
tick_label = label,
color = fill_color,
edgecolor = edge_color,
width = 0.3,
hatch = hatch,
yerr = error_y,
)
#set title
fig.suptitle("bar graph")
ax.set_title("option test")
plt.tight_layout()
#set graph to tkinter window
canvas = FigureCanvasTkAgg(fig, root)
toolbar = NavigationToolbar2Tk(canvas, root)
canvas.get_tk_widget().pack() #show graph
plt.close()
root.mainloop()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment