I am making a parser for Stepmania and using the data the program compiles to turn into graphs. I am trying to make the scatterplot graph not make the dots bigger as it moves upwards but I am unsure of how to do that. I looked at the matplotlib markersize modifier but it hasn't been working in my function and I think I need someone to explain it to me. Please help.
from tkinter import *
from tkinter import ttk
from tkinter import filedialog
from PIL import ImageTk, Image
import numpy as np
import matplotlib.pyplot as plt
import os
import glob
import matplotlib
directions = []
nameDirections = []
root = Tk()
nameDirections = ["left", "down", "up", "right"]
directions = []
#NameDirections are the type of arrows that are being measured.
#Directions contains the numbers that measure the amount of times each direction is in the text file for a Dance Dance Revolution game code
e = Entry(root, width=50)
e.pack()
root.title("Insert GUI Title Here")
root.geometry('600x400')
root.resizable(False, False)
#Size of GUI
def openFolder():
folPath = filedialog.askdirectory()
return folPath
def openSmFile():
folPath = filedialog.askopenfilename()
return folPath
#Opens an SM file (Stepmania code file)
def checkDirections():
folPath = openFolder()
for fpath in glob.iglob(f'{folPath}/*'):
if (fpath.endswith('.sm')):
file = open(fpath, "r")
lines = []
lines = file.readlines()
left = 0
down = 0
up = 0
right = 0
beats = 0
for line in lines:
i = 0
if not ("," in line or "." in line or "#" in line or ";" in line or "-" in line or line == "" or len(line) != 5):
for alpha in line:
if i == 0 and alpha != "0":
left = 1
if i == 1 and alpha != "0":
down = 1
if i == 2 and alpha != "0":
up = 1
if i == 3 and alpha != "0":
right = 1
i = 1
beats = 1
print("The file name is " str(fpath))
print("There are " str(left) " lefts in this song.")
print("There are " str(down) " downs in this song.")
print("There are " str(up) " ups in this song.")
print("There are " str(right) " rights in this song.")
print("There are " str(beats) " beats.")
#Prints number of each type of arrow. This was taken from code I wrote earlier and I just changed it up for the near-identical function below that returns instead
#Because i was too lazy to make a good solution
def graph(thing):
fpath = openSmFile()
if (fpath.endswith('.sm')):
file = open(fpath, "r")
lines = []
lines = file.readlines()
left = 0
down = 0
up = 0
right = 0
for line in lines:
i = 0
if not ("," in line or "." in line or "#" in line or ";" in line or "-" in line or line == ""):
for alpha in line:
if i == 0 and alpha != "0":
left = 1
if i == 1 and alpha != "0":
down = 1
if i == 2 and alpha != "0":
up = 1
if i == 3 and alpha != "0":
right = 1
i = 1
directions = [left, down, up, right]
plt.title(str(os.path.basename(fpath)))
if (thing == "bar"):
plt.bar(nameDirections, directions)
if (thing == "pie"):
plt.pie(directions, labels=nameDirections, autopct='%1.1f%%',shadow=True, startangle=90)
if (thing == "scatter"):
plt.scatter(directions, nameDirections)
else:
print("This file is not valid.")
def ScatterTime():
fpath = openSmFile()
if (fpath.endswith('.sm')):
file = open(fpath, "r")
lines = []
lines = file.readlines()
beats = []
arrowDirections = []
beat = 1
for line in lines:
i = 0
if not ("," in line or "." in line or "#" in line or ";" in line or "-" in line or line == "" or ":" in line or len(line) != 5):
for alpha in line:
if i == 0:
arrowDirections.append("left")
if i == 1:
arrowDirections.append("down")
if i == 2:
arrowDirections.append("up")
if i == 3:
arrowDirections.append("right")
i = 1
if i != 5:
if (alpha != "0"):
beats.append(beat)
if (alpha == "0"):
beats.append(0)
beat = 1
plt.title(str(os.path.basename(fpath)))
fullrange = list(range(1, beat))
u, ind = np.unique(arrowDirections, return_inverse=True)
plt.xticks(range(len(u)), u)
plt.scatter(ind, fullrange, s=beats, marker = ".",)
else:
print("This file is not valid.")
#Creates a scatterplot
def testFunction():
fpath = openSmFile()
if (fpath.endswith('.sm')):
file = open(fpath, "r")
lines = []
lines = file.readlines()
for line in lines:
i = 0
if not ("," in line or "." in line or "#" in line or ";" in line or "-" in line or line == "" or ":" in line or len(line) != 5):
print(line)
print(len(line))
else:
print("This file is not valid.")
#Not relevant. Tests arrays in function
def bar():
graph("bar")
plt.show()
#Creates a bar graph
def ILovePie():
graph("pie")
plt.show()
def Scatter():
ScatterTime()
plt.show()
#Creates a pie graph
barGraph = Button(root, text="Click to show a bar graph", command=bar)
pieGraph = Button(root, text = "Click to show a pie graph", command = ILovePie)
runThrough = Button(root, text="Click to print number of each arrow", command=checkDirections)
scatterGraph = Button(root, text = "Click to show a scatterplot", command = Scatter)
testButton = Button(root, text = "Test", command = testFunction)
barGraph.pack()
runThrough.pack()
pieGraph.pack()
scatterGraph.pack()
testButton.pack()
root.mainloop()
#Creates the buttons to show the graphs and the run text command
CodePudding user response:
In ScatterTime()
, you have this line:
plt.scatter(ind, fullrange, s=beats, marker = ".",)
s
corresponds to the marker size, so whatever beats
is, that's the size of your marker. See the matplotlib documentation on
Here in your code, value in beats
is controlling the markers' size, aligning the value in beats
to 1
will align the markers' size
code:
def ScatterTime():
fpath = openSmFile()
if (fpath.endswith('.sm')):
file = open(fpath, "r")
lines = []
lines = file.readlines()
beats = []
arrowDirections = []
beat = 1
for line in lines:
i = 0
if not ("," in line or "." in line or "#" in line or ";" in line or "-" in line or line == "" or ":" in line or len(line) != 5):
for alpha in line:
if i == 0:
arrowDirections.append("left")
if i == 1:
arrowDirections.append("down")
if i == 2:
arrowDirections.append("up")
if i == 3:
arrowDirections.append("right")
i = 1
if i != 5:
if (alpha != "0"):
beats.append(1)
if (alpha == "0"):
beats.append(0)
beat = 1
plt.title(str(os.path.basename(fpath)))
fullrange = list(range(1, beat))
u, ind = np.unique(arrowDirections, return_inverse=True)
plt.xticks(range(len(u)), u)
plt.scatter(ind, fullrange, s=beats*10, marker = ".",)
else:
print("This file is not valid.")
#Creates a scatterplot