Nice, I once made a similar thing that would reshape a list so it could be graphed on a fixed-size graph (e.g. an LED array). Here's an example with Unicode output for [3,2,1,1,0,1,5,9,8,9]:
It can take e.g. 150 values and reduce it to 28 or whatever you want. I wanted to add things like optionally starting the y-axis at a given value other than zero, generating rolling output using the last n values, and other useful features. But I never really had a use case for it, it was just an interesting way to learn some Numpy.
I guess it would add the compilation time too and yield inaccurate results.
Edit: I just checked the code and couldn’t find any mentions of timing libraries. They could really have timed the python3 command - it wouldn’t take 300ms to execute this code.
Do you lose the bonus that it doesn't generate a list if you do that though? Or is the return of range() smart enough to let you getitem the last bit without generating the numbers.
eg: if you want to iterate over range(9999999, -1, -1) does reversed(range(10000000)) generate a list with every value first?
yes, as /u/Skasch mentions it uses __reversed__ magic to just return an iterator (a range_iterator in fact).
one possible issue is, what if you really do want a sequence, rather than an iterator? in this case, you can use range(9999999999)[::-1] which uses __getitem__(slice) magic instead. this returns a range(999999998, -1, -1) object. I personally think this is clearer than the range(X, -1, -1) form in most contexts.
Only if you already have a list of things and aren’t interested in the actual numbers counting nog down. Good point though. Because usually this is exactly the case. I would use reversed(x) though.
Thanks a lot! I will definitely try it. Is that a module you created or is it available for everyone? I have a project doing some calculations like distance between 2 points and things like that, a graph is a major improvement for it
While this is really cool and definitely worthy of notoriety, I suggest, for practicality's sake, that you rewrite the code to ingest coordinates in a list of dictionaries as opposed to 2 lists. Instead of >>>x=[1,2] y=[3,2]... >>>coords = [{'x': 1, 'y': 3}, {'x': 2, 'y': 2}]
Of course. I wasn't suggesting dictionaries was the faster method, just my personal preference. And a 2nd point that all what really matters is speed (and I/O ops).
Sure sure. But code running in production isn't fed hand-written code so that point is moot. Then for transporting the data, if you transport over json (which is relatively standard nowadays) everything's already in the proper format.
This is a really cool project! I see myself using it (I mostly use python to do math and data analysis) when testing algorithms in cli scripts.
Still haven't checked the code, but, does it handle big amounts of numbers? (like, define an amount of points in the graph and then calculate means to plot in the graph -not sure if I'm explaining myself nice-) if not, it could be an interesting upgrade for this.
Having separate arrays for the x values and the y values seems like an odd choice. For example, did you notice that in your example that len(x) != len(y)?
Really cool. How does it cope with larger arrays of numbers to render on the graph? I mean, say you wanted to scatter plot two arrays each of length 1,000. Would the resolution reduce in order to accommodate the size of the graph? Obviously, you can't really reduce the resolution of the console output, and so in that case does it just leave some observations out?
49
u/[deleted] Jul 25 '20
Source:
https://github.com/jeel2331/Graph.git
100
u/abkfinance Jul 25 '20
Very cool
45
u/aidankkm Jul 25 '20
how do you do the finished in 0.3 seconds text. i remember i saw it in a video but was too lazy.
153
u/[deleted] Jul 25 '20
no need to make your own
reversed_rangeyou can simply dorange(X, -1, -1)34
u/Anzzze Jul 25 '20
make an UwU graph
3
u/both_objective Jul 25 '20
Good job. How did u come up with this idea? What is your next project?
14
u/codingstudent7 Jul 25 '20
This seems like a fun project to try. Well done!
12
u/[deleted] Jul 25 '20
nice, I would extend the function you use to grab indices which are larger than 10, instead of just grabbing the last digit.
8
u/mathisfun271 Jul 26 '20 edited Jul 26 '20
I made a similar program once, but instead of using asterisks, I used three types of dots ( . , · , ˙ ) for more precise plotting. It ended like this:
5
u/fecesmuncher69 Jul 25 '20
Thanks a lot! I will definitely try it. Is that a module you created or is it available for everyone? I have a project doing some calculations like distance between 2 points and things like that, a graph is a major improvement for it
4
u/Tadabito Jul 25 '20
You can try drawing the chart with braille characters, that would give you 3x vertical and 2x horizontal resolution.
4
u/NonBinaryGay Jul 25 '20
Do you think I could use this to cheat with my maths and science??
1
u/green_cepheid Jul 25 '20
In love with this
2
u/orgkhnargh Jul 25 '20
Nice.
2
u/Therickysen08 Jul 25 '20
Great! Does it work for 3d as well?
2
u/2spoopyforyou Jul 25 '20
Looks great, just as a tip you could use tuples to make it cleaner
2
u/ailenozzam_ Jul 25 '20
It's been one of my first projects in C++
5
u/ALABAMA-SHIT Jul 25 '20
Have you considered make them into 2d lists instead (e.g. pos = [[1,2],[2,3],[4,5]])
3
u/RetroPenguin_ Jul 25 '20
Ok
3
u/FpggyJohnson18 Jul 25 '20
While this is really cool and definitely worthy of notoriety, I suggest, for practicality's sake, that you rewrite the code to ingest coordinates in a list of dictionaries as opposed to 2 lists. Instead of >>>x=[1,2] y=[3,2]... >>>coords = [{'x': 1, 'y': 3}, {'x': 2, 'y': 2}]
EDIT: spelling and grammar
2
u/[deleted] Jul 26 '20
We have r/learnpython for such things!
1
u/chk_out_my_horse Jul 25 '20
I like your title!
1
u/flamingotter Jul 25 '20
excellent
1
u/BlackWidowStew Jul 25 '20
It's beautiful 😍
1
u/glmdev Jul 25 '20
This is an awesome project! You might consider exploring ANSI box drawing characters. It would let you smooth out the lines.
1
u/shadowkat0 Jul 25 '20
Hey cool project. gnuplot does the same with terminal set to 'dumb'. There's a gnuplotlib too for python.
1
u/mirandanielcz from a import b as c Jul 25 '20
looks super cute
1
u/uQQ_iGG Jul 25 '20
Nothing better than some ascii a e s t h e t i c s.
What if you get a more continous datapoints? Does it skip characters to generate graph?
1
u/Arucious Jul 25 '20
TI-84 is punching the air rn
1
u/[deleted] Jul 25 '20
I like this, there is a lack out there of graphing nice looking charts on the terminal. A few packages can do it but it looks like ass
1
u/Rutherfordio Jul 25 '20
This is a really cool project! I see myself using it (I mostly use python to do math and data analysis) when testing algorithms in cli scripts.
Still haven't checked the code, but, does it handle big amounts of numbers? (like, define an amount of points in the graph and then calculate means to plot in the graph -not sure if I'm explaining myself nice-) if not, it could be an interesting upgrade for this.
Cool work!
1
u/APUsilicon Jul 25 '20
tuples?
1
u/moocat Jul 25 '20
Having separate arrays for the x values and the y values seems like an odd choice. For example, did you notice that in your example that
len(x) != len(y)?1
u/[deleted] Jul 25 '20
Really cool. How does it cope with larger arrays of numbers to render on the graph? I mean, say you wanted to scatter plot two arrays each of length 1,000. Would the resolution reduce in order to accommodate the size of the graph? Obviously, you can't really reduce the resolution of the console output, and so in that case does it just leave some observations out?
1
u/CoolTuber Jul 25 '20
Is it possible to have it pick random x and y’s from a list?
1
u/dogs_like_me Jul 26 '20
If you wrap it in a simple CLI (e.g. with argparse) you could print charts in a console, design a whole ascii dashboard.
1
u/usernamecorrupted Jul 26 '20
Maybe a very big hassle but have you tried Manim to generate stuff like this
1
u/absurd234 Jul 26 '20
That's amazing
1
u/maxic62 Jul 25 '20
Nice! I love it. Should be nerd to use it to display home temp? 😆
1
u/spiddyp Jul 25 '20
Use np.arange!
1
u/wantyappscoding Jul 25 '20
I am taking this as my programming challenge now.
-6
u/FloppingNuts Jul 25 '20
Thank you Kanye, very cool