r/pygame • • Sep 22 '26

Pygame Chart Library

Hello, just wanted to share this library project with people that migth actually care about.

This is a library im making for pygame to make plot graphs and chart easier and convenient, because as far as im aware theres no library to add charts directly onto pygame. Now, the code is problably very confusing and unoptimized because 1 - im still learning python and stuff, ive been coding for a few years all self taugth, so im still not the best, but i enjoy making this project and 2 - im dumb and didnt used librarys like numpy so my code is a mess of nested arrays and dictionarys

Either way my compression method(currently theres only one, but im planning to add more for diferen use cases) as managed to make the graph stable forever, before that the fps would drop after 20 seconds of data, but now you can run a chart forever and whatever program you are running should keep the fps(allegdely, havent tested for more than 10 minutes, but im running thoose tests tonigth)

Currently the library works around 2 main classes, the DataGroup and the Graph, the DataGroup class is a group of diferent metrics, with one metric being declared as the abcissa, so every other metri in the data group is around that metric. The class has methods like comrpess data, and a function called add_data which you can use to intuitivly add more data to the group. Furthermore the class has a method called update_graphs, that grabs every graph thats associated with this class(you can manually assocaite graphs, or you can pass the dataGroup as an argument when creating a graph) and updates making the graphs draw themself again.

The Graph class has a lot of internal methods that are used to calculate the magnitues of the grids, draw the labels and all of that stuff, calculate the points and then draw the points. Currently theres only plot charts but in the future i want to add at least pie charts to the lib. When creating a class object you pass a DataGroup as an argument to associate it, you also pass a hex color array to determine the colors of each metric, and a config array which is optional, is more for personalized looks, but you mostly wont change.

Overall im pretty proud of my library, it feels rly professional and something that people would actually use, so you if you think that its something that i should publish just say it that i would be very happy too, i could even get feedback because, again, im kinda bad at programming, so actualyl talented peopel could tell me all the mistakes i did.

This is my library being used in another project(a natural evolution simulator) you can see that it works althougth the conditions i puted it in arent the best(too many metrcis in one group, and a rly small graph)

PS: AI was only and solely used to debug, and even there it was moslty useless because my nested dicts and arrays were too confusing for ai and only my head could actually visualize it(with lots of efforts)

20 Upvotes

9 comments sorted by

2

u/DanielTheTechie Sep 23 '26

As Linus Torvalds said, talk is cheap, show me the code.

2

u/Agile-Group-1354 Sep 23 '26

https://github.com/Quartef12345/Natural-Selection-Simulation/tree/main/quartef_pygame_graphs

This is the folder related to the chart library, but its inside another project beacuse is started working on it there, and now im to lazy to change to a separate project

1

u/Agile-Group-1354 Sep 23 '26

Ale bro, just let me get in my pc

2

u/PyLearner2024 Sep 25 '26

That's cool. Is there a specific reason you want to display plots in pygame specifically rather than use an existing plotting library?

1

u/Agile-Group-1354 Sep 26 '26

well, as far as im aware ther wanst any plot library for pygame, but i was searching graphs and not plot or chart, because from my lanugage portuguese the word we use for plots and charts is "gráficos" which is similar to graphs and in english graphs resembles 3d graphs and stuff more than it ressembles charts and plots, so that made my search pretty useless, im aware of somre libs that do plots like matplotlib, but they required an extra window for the them, which is not what i wanted i was looking for native pygame compatibility. I also just like challenges and this is something that defintly was one, choosing data structures and getting the points positions and all of that.

1

u/SignedInt32 Sep 22 '26

Looks awesome! thumbs up from me!

1

u/Agile-Group-1354 Sep 22 '26

thanks bro, means a lot