mkaz / termgraph Goto Github PK
View Code? Open in Web Editor NEWa python command-line tool which draws basic graphs in the terminal
License: MIT License
a python command-line tool which draws basic graphs in the terminal
License: MIT License
https://www.python.org/dev/peps/pep-0563/#enabling-the-future-behavior-in-python-3-7
README.md states that the minimum version is Python 3.5+, but that is incorrect.
when using --stack
and --width
together, the width is determined by the highest single value in the series, setting all other values as a proportion of that, greatly extending the width beyond what is designated, and making it impossible to designate a desired width when working with values that are not known ahead of time.
$ cat <<EOF | termgraph --custom-tick="X" --stack --width=10
test1 10 20 40 40 40
test2 10 20 40 40 10
test3 10 10 10 10 10
EOF
test1: XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX 150.00
test2: XXXXXXXXXXXXXXXXXXXXXXXXXXXXX 120.00
test3: XXXXXXXXXX 50.00
Why in horizontal bar chart line following 0.0 value Is grey out?
Here's example to reproduce the problem:
from termgraph.termgraph import chart
data = [[0],[34], [2]]
labels = ["Cars", "Boats", "Planes"]
args = {
"histogram": False,
"stacked": False,
"width": 50,
"no_labels": False,
"no_values": False,
"format": "{:.0f}",
"suffix": "",
"vertical": False
}
chart(None, data, args, labels)
Hello!
Is it possible to pipe in the output of sort | uniq -c?
This a basic bash one liner to get distributions.
grep "^." MyFile.tsv | cut -f2 | sort | uniq -c | sort -nr
yields
25401 1
23593 7
21999 0
21760 3
20276 4
19462 10
19301 8
18835 5
18413 6
Where the first column are the values, labels are after the white space.
grep "^." MyFile.tsv | cut -f2 | sort | uniq -c | sort -nr | termplot.py
plots the labels (that happen to be numeric as well)
25401: ▇▇ 1
23593: ▇▇▇▇▇▇▇▇▇▇▇▇▇▇ 7
21999: | 0
21760: ▇▇▇▇▇▇ 3
20276: ▇▇▇▇▇▇▇▇ 4
19462: ▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇ 10
19301: ▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇ 8
18835: ▇▇▇▇▇▇▇▇▇▇ 5
18413: ▇▇▇▇▇▇▇▇▇▇▇▇ 6
18406: ▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇ 9
17906: ▇▇▇▇ 2
17153: ▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇ 14
16755: ▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇ 13
14757: ▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇ 12
14531: ▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇ 11
Thank you!
Abel
Hey, I am facing following issue when trying too tun termgraph
. Problem could be with my terminal setting but I am unsure how to debug it. Kindly help
Traceback (most recent call last):
File "/home/avi/.local/bin/termgraph", line 10, in <module>
sys.exit(main())
File "/home/avi/.local/lib/python3.7/site-packages/termgraph/termgraph.py", line 151, in main
chart(colors, data, args, labels)
File "/home/avi/.local/lib/python3.7/site-packages/termgraph/termgraph.py", line 394, in chart
print_row(*row)
File "/home/avi/.local/lib/python3.7/site-packages/termgraph/termgraph.py", line 255, in print_row
sys.stdout.write(TICK)
UnicodeEncodeError: 'latin-1' codec can't encode character '\u2587' in position 0: ordinal not in range(256)
Install via pip3 install termgraph
. Running termgraph --help
works fine
SHELL : fish, version 3.0.2
OS debian linux
Distributor ID: Parrot
Description: Parrot GNU/Linux 4.7
Release: 4.7
Codename: n/a
termgraph should run on linux shell without problem
termgraph throws error UnicodeEncodeError: 'latin-1' codec can't encode character '\u2587' in position 0: ordinal not in range(256)
pip3
tool/data
directorytermgraph ex1.dat
etcWhen piping termgraph
to head
, and I assume other commands that do not process the whole pipe stream, a BrokenPipeError
is raised.
$ cat <<EOF | termgraph | head -n 5
2021-05-30 15
2021-05-29 20
2021-05-28 21
2021-05-27 19
2021-05-26 19
2021-05-25 18
2021-05-24 18
2021-05-23 19
2021-05-22 19
EOF
2021-05-30: ▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇ 15.00
2021-05-29: ▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇ 20.00
2021-05-28: ▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇ 21.00
2021-05-27: ▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇ 19.00
Traceback (most recent call last):
File "/home/dho/.local/bin/termgraph", line 8, in <module>
sys.exit(main())
File "/home/dho/.local/lib/python3.8/site-packages/termgraph/termgraph.py", line 130, in main
chart(colors, data, args, labels)
File "/home/dho/.local/lib/python3.8/site-packages/termgraph/termgraph.py", line 487, in chart
for row in horiz_rows(
File "/home/dho/.local/lib/python3.8/site-packages/termgraph/termgraph.py", line 282, in horiz_rows
print(label, end="")
File "/usr/lib/python3/dist-packages/colorama/ansitowin32.py", line 41, in write
self.__convertor.write(text)
File "/usr/lib/python3/dist-packages/colorama/ansitowin32.py", line 162, in write
self.write_and_convert(text)
File "/usr/lib/python3/dist-packages/colorama/ansitowin32.py", line 190, in write_and_convert
self.write_plain_text(text, cursor, len(text))
File "/usr/lib/python3/dist-packages/colorama/ansitowin32.py", line 196, in write_plain_text
self.wrapped.flush()
BrokenPipeError: [Errno 32] Broken pipe
Exception ignored in: <colorama.ansitowin32.StreamWrapper object at 0x7f9016207310>
BrokenPipeError: [Errno 32] Broken pipe
$ termgraph --version
termgraph v0.4.2
$ python3 --version --version
Python 3.8.5 (default, Jan 27 2021, 15:41:15)
[GCC 9.3.0]
$ uname -a
Linux litten 5.4.0-73-generic #82-Ubuntu SMP Wed Apr 14 17:39:42 UTC 2021 x86_64 x86_64 x86_64 GNU/Linux
I am using Chart to show a bar graph and the individual "TICK" marks show up as question mark. Been trying to debug it and I was able to make it work when I change TICK from the defined quoted value to
TICK = u"\u2588"
At that point I get a solid color block in whatever color defined. I tried to
from termgraph import termgraph as tg
from collections import defaultdict
C = tg.AVAILABLE_COLORS
TICK = u"\u2588"
tg.chart (
colors=[C["green"] , C["yellow"]] ,
data=[[nft , og]] ,
args=defaultdict (bool ,
{
"stacked" : True ,
"custom_tick": TICK,
"width" : 60 ,
"format" : "{:<5.2f}" ,
"no_labels" : True ,
"suffix" : f" (NFT:{nft} ({nft_pct:.0f}%), OG:{og} ({og_pct:.0f}%))"
} ,
) ,
labels=[""] ,
)
and the class would not reflect the overwrite of the TICK variable passed. I reviewed the code of the library and the TICK is a global value that is changed when is passed via the argument, but not when I import the package.
What do you recommend is the best approach to fix the definition of TICK so that it will show properly in windows 10.
-- Adonis
Is this module available as a third-party module? If yes, how to integrate. If not, what are your plans?
The last release crashes on my https://github.com/boxed/test-benchmarks project.
https://github.com/mkaz/termgraph/blob/master/termgraph/termgraph.py#L420
https://github.com/mkaz/termgraph/blob/master/termgraph/termgraph.py#L220
These lines should presumably do args.get('label_before')
.
If I change to doing .get
everything works for me at least.
I'm using print_blocks in a script and only passing integers to it, but it always format it with decimal places.
I want to plot histogram by Termgraph.
When I want to visualize some data, I often want to see the distribution by histogram.
So, given the use case of termgraph, I think it is the function we want
Example of histogram by Pandas is as follow:
data = np.random.normal(10, 10, 1000) # generate dummy data follow normal distribution
df = pd.DataFrame({'col': data})
df.hist()
My expected output example in termgraph is as follow:
$ termgraph hist.dat --histogram --bins 5
-20 - -10: ▇▇▇▇▇▇▇ 7
-10 - 0: ▇▇▇▇▇▇▇▇▇ 9
0 - 10: ▇▇▇▇▇▇▇▇▇▇▇ 11
10 - 20: ▇▇▇▇▇▇▇▇▇ 9
20 - 30: ▇▇▇▇▇▇▇ 7
If it is good, I will work on this function and make a PR.
I intended to submit a pull request on bug fixes, however, the existing tests are largely broken.
I just clone the main branch of termgraph (to be exact, commit 63491d8), and run pytest tests
. It outputs a bunch of errors, showing test statistics at the end:
================ 16 failed, 21 passed in 0.63s ==================
Could you please fix these tests? @mkaz
Hi, thanks a ton for this nifty package !
It'd be useful if we could overwrite the individual bar labels.
echo "Label,3,9,1" | termgraph --custom-tick "😀" --no-label --row-values {three, nine, whatever}
Would output:
😀😀😀 three
😀😀😀😀😀😀😀😀😀 nine
😀 whatever
Alternatively, one could provide custom suffixes for each row (currently one can only append a single suffix to all rows).
Hey there. So I was wondering if there are some way to make the graph become progressive, since it reads new data on the new next line in a file. Here is my snippet on the Bash script.
#!/bin/bash
while IFS= read -r each_stat; do
echo "$each_stat" > "log/each_result.csv" & wait
termgraph "log/each_result.csv" --color {cyan,red,yellow,green}; sleep 0.01s
printf "\033[6A ";
done < "log/result.csv"
First I passed each line of the file to a temp file, so termgraph can read only one data at a time. then I return the cursor 6 line before and continue to read the next data. But its not updating the bar quite what I wanted to, which become overlapped with the previous bar. Are there any solution to overwrite the previous one, without clearing the screen ?
Thanks for the opportunity, really cool stuff !
Is it possible to plot a pandas dataframe with termgraph?
Or is there any other work around for getting the dataframe to be plotted on terminal ?
It'll be great if termgraph
can accept reading input from stdin from uniq -c
result.
Specifically, how to set up project locally (install deps, run tests). I'm used to setting up apps, not libraries, so my background is using requirements.txt
or pyproject.toml
and pip or Poetry to install those deps, so apologies if this issue covers something that would be obvious to a library developer.
Recently I wanted to make a data analysis chronicle, only with terminal based tools. Then I found termgraph
<3
Finally I could implement my idea.... even better than expected, so I wanted to thank you for your great tool and show yo can could be achieved thanks to your software :
Hopefully you'll like it.
Kind Regards;
Adrien
Would be great to be able to pull this in as a dependency on some other projects. Are you interested in adding it pypi?
At the moment, termgraph uses many functions inside one script to achieve its goal. It works well, but it might be better to use classes and a more object-oriented approach. This would make it more organized, easier to build upon and easier to re-use in other projects.
The problem is that it will change a lot of the existing code structure, meaning it will break other projects which use termgraph unless they adopt these changes.
The upside is that it will make future development easier, and it will be easier for others to use this library in their own project. For example, it would make #27 easy to fix.
However, I understand if this project has progressed too far for this to be done, and restructuring all the code might not be worth the effort. But I am willing to do this myself, I have enough time available and this would be a good learning opportunity.
Hi.
I am quite enjoying termgraph; so, first of all, thanks for sharing this nice tool.
I've got few questions and perhaps feature requests.
In the attached (draft) figure, every bar adds up to 100%, because the values are in percentage. Therefore, it does not make sense to print the sum (i.e. "100") to the right of each bar, anymore. Is there a way to suppress it (e.g. via args)?
Sometimes a row contains zeros, e.g. for "superdome" the values are basically a 100 and bunch of zeros. Is that the reason that the rightmost end of all rows do not line up? Is there a way to fix this?
There are two newline spaces between the category printout and the actual bars. Is it possible to let the user decide this (via args)?
Kind regards
Ehsan
The code currently does not follow PEP8. By following the style guide, the code would be more readable, consistency would be better and it would be easier to maintain.
When I run pylint
on termgraph.py
, it outputs a large amount of warnings:
()
and []
, i.e. parser.add_argument( '--title', help='Title of graph' )
should be parser.add_argument('--title', help='Title of graph')
It might also be better to use classes and a more object-oriented approach. This would make it more organized, easier to build upon and easier to re-use in other projects. Although this might better be filed as a new issue.
The display in column doesn't work properly with the --stacked option.
Example1: ▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇ 22.00
Longertext example : ▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇ 36.00
I have to use column -t -s ':'
to clean it up.
When the maximum value is less than the width, termgraph should scale it up to the width rather than refusing to normalize. Problem is at https://github.com/mkaz/termgraph/blob/master/termgraph/termgraph.py#L189.
Otherwise you can never meaningfully plot things like probabilities, which are always between 0-1.
I believe if you simply delete lines 189-192, this will fix itself as the norm factor can handle rescaling up.
The new API module as defined in #27 and #75 cannot be imported:
>>> from termgraph.module import Data, BarChart, Args, Colors
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/home/user/.local/share/virtualenvs/foo-IGGZy7fP/lib/python3.9/site-packages/termgraph/module.py", line 12, in <module>
from utils import cvt_to_readable
ModuleNotFoundError: No module named 'utils'
Hi there,
Thank you very much for providing this library!
I'm attempting to use it to print a live indicator as a debugging aid. (I'm charting how much GPU memory is used vs free). I'm setting width=60 on every call. However, the total bar width changes when the data changes!
I'm wondering if the issue is with normalization not accounting for stacked charts?
In case it helps, here's how I'm calling it:
from collections import defaultdict
import time
from gpustat import core as gpus
from termgraph import termgraph
C = termgraph.AVAILABLE_COLORS
while True:
# Settings
gpu_idx = 7 # TODO: cmd line
info = gpus.new_query()
gpu = info[gpu_idx]
termgraph.chart(
colors=[C["red"], C["yellow"]],
data=[[gpu.memory_used, gpu.memory_free]],
args=defaultdict(
bool,
{
"stacked": True,
"width": 60,
"format": "{:<5.2f}",
"no_labels": True,
"suffix": f" (used: {gpu.memory_used}, free: {gpu.memory_free})",
},
),
labels=[""],
)
time.sleep(1)
Many thanks for any tips, and apologies if I'm confused here!
I've tried the examples provided in a readme, but never got any result: the error is always argument --color: invalid choice
.
Python is 3.6.5
Thanks for making this tool. I am not sure if this is a bug, or I am missing something, but I wanted to bring it up.
Shouldn't the values for each of the bins add up to 3 since there are 3 rows in the data?
§ termgraph --version
termgraph v0.4.2
§ echo $'1 100\n2 200\n3 300' | termgraph --histogram
100 – 140.0: ▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇ 1.00
140.0 – 180.0: 0.00
180.0 – 220.0: ▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇ 1.00
220.0 – 260.0: 0.00
260.0 – 300.0: 0.00
Also, if the input has values that are same, there is an error:
§ echo $'1 100\n2 100' | termgraph --histogram
Traceback (most recent call last):
File "/usr/local/bin/termgraph", line 10, in <module>
sys.exit(main())
File "/Library/Python/3.7/site-packages/termgraph/termgraph.py", line 130, in main
chart(colors, data, args, labels)
File "/Library/Python/3.7/site-packages/termgraph/termgraph.py", line 478, in chart
for row in hist_rows(data, args, colors):
File "/Library/Python/3.7/site-packages/termgraph/termgraph.py", line 217, in hist_rows
normal_counts = normalize(count_list, args["width"])
File "/Library/Python/3.7/site-packages/termgraph/termgraph.py", line 162, in normalize
norm_factor = width / float(max_datum)
ZeroDivisionError: float division by zero
Hello, awesome folks developing termgraph.
I have recently build a utility which displays useful git information in a presentable colored graphs (of course using termgraph) on terminal. I am really enjoying the reports :)
Wanted to check if there is any support for pie-charts (like this project) is planned for the future releases or not ??
Since I enjoy this tool so much, I am willing to spend some time on it and maybe prepare a feature request for it myself, but I might need some help and guidance :D Free free to drop the plan in comments as to how such a feature could be implemented in this project.
Thanks and cheers
I was just testing and running things with termgraph when I noticed that the colors of the graphs seemed a little off. I thought it might the color scheme of Windows Terminal. But on further checking, I found out that the color codes in colorama.Fore
and the ones in termgraph
are different. Below is the code I ran for checking it.
I hope you update the colors accordingly if needed.
some error
File "termgraph.py", line 163
sys.stdout.write( f'\033[{color}m' ) # Start to write colorized.
^
SyntaxError: invalid syntax
i fix it by remove all "f"
sys.stdout.write( '\033[{color}m' )
This is very cool, and it can me made even more useful by adding it to PyPi.
This would allow people to easily install it with pip, instead of requiring manual steps to: install pre-requisites, download the script and copy it to a location on the path.
I can submit a PR that prepares the repo for PyPi:
setup.py
readme.md
to readme.rst
After merging the PR, all you would need to do is:
Let me know if you're interested in this. As an example, here's one of my repos that's registered in PyPi
to solve the over length of bar problem for me (as i have really big number in prediction)
it's about the find_max function , the original function only find the biggest number in target array, so i change the fucnction to:
def find_max(list_):
"""Return the maximum value in sublist of list."""
m1=max([sublist[-1] for sublist in list_])
m2 = max([sublist[0] for sublist in list_])
return max([m1,m2])
and solved my problem :)
If termgraph is used as a module and a value is 0, a ValueError: math domain error
is thrown by math.log
in utils.py::cvt_to_readable(num)
here:
Line 16 in 09e17cc
Problem is that there is there is no zero check for num. This is done correctly in termgraph.py::cvt_to_readable(num)
:
termgraph/termgraph/termgraph.py
Line 197 in 4aa3b67
In the source code there is no check for reading from information files
First of all: thank you so much for this neat library, appreciate all the work that has gone into making this :)
I am trying to make a graph from within another Python script, and here's a working version:
In [1]: from termgraph.termgraph import stacked_graph, AVAILABLE_COLORS, normalize, chart
...:
...: labels = ["size 1", "size 10", "size 100"]
...: data = [
...: [1, 1, 10],
...: [1, 10, 100],
...: [1, 100, 120],
...: ]
...: colors = [
...: AVAILABLE_COLORS.get("green"),
...: AVAILABLE_COLORS.get("yellow"),
...: AVAILABLE_COLORS.get("red"),
...: ]
...: args = {
...: "no_labels": False,
...: "format": "{:<5.2f}",
...: "suffix": "",
...: "stacked": False,
...: "histogram": False,
...: "width": 50,
...: "different_scale": False,
...: "no_values": False,
...: "vertical": False,
...: }
...: chart(colors, data, args, labels)
size 1 : ▏ 1.00
▏ 1.00
▇▇▇▇ 10.00
size 10 : ▏ 1.00
▇▇▇▇ 10.00
▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇ 100.00
size 100: ▏ 1.00
▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇ 100.00
▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇ 120.00
However, if I change args["vertical"]
to True
, I get ...
In [2]: args["vertical"] = True
...: chart(colors, data, args, labels)
...:
(no output)
Maybe I am switching up args weirdly or something, looked through the Readme and I may have missed any misc. requirements for vertical. Appreciate any help, will keep digging though!
Of course as soon as I post this I find...
https://github.com/mkaz/termgraph/blob/main/termgraph/termgraph.py#L465
Adding "different_scale": True,
made something print, but it seems rather broken.
I cant initialize the termgraph command. Neither for 2.7 or 3.5:
I installed via pip and pip3
python 2.7:
odit@atlas:pts/0->/home/odit (0)
> termgraph
Traceback (most recent call last):
File "/home/linuxbrew/.linuxbrew/bin/termgraph", line 7, in <module>
from termgraph.termgraph import main
File "/home/linuxbrew/.linuxbrew/Cellar/python@2/2.7.14_4/lib/python2.7/site-packages/termgraph/termgraph.py", line 172
sys.stdout.write( f'\033[{color}m' ) # Start to write colorized.
^
SyntaxError: invalid syntax
Python3.5:
Traceback (most recent call last):
File "/home/odit/.local/bin/termgraph", line 7, in <module>
from termgraph.termgraph import main
File "/home/odit/.local/lib/python3.5/site-packages/termgraph/termgraph.py", line 172
sys.stdout.write( f'\033[{color}m' ) # Start to write colorized.
^
SyntaxError: invalid syntax
It could be nice to have the option to format the output as left-aligned, based on labels length or given fixed width. It makes comparisons and overall output easier to read imo
Basic suggested impl:
def horiontal_rows( labels, data, normal_dat, args, colors ):
val_min = findMinMax( data, 'min' )
# Find longest label for aligned output
length_min = 0
for i in range(len(labels)):
if len(labels[i]) > length_min:
length_min = len(labels[i])
for i in range( len( labels ) ):
if args['no_labels']:
# Hide the labels.
label = ''
else:
label = "{:<{x}}: ".format( labels[i], x = length_min )
...
File README.md
mentioned several examples, and the ones contains argument --no-title
are not functioned as expected.
$ echo "Label,3,9,1" | termgraph --custom-tick "😀" --no-title --no-labels
termgraph: error: unrecognized arguments: --no-title
When passing in data containing all 0's termgraph will return a ZeroDivisionError. Ideally termgraph should accept this value and return an empty graph.
termgraph.chart(
colors=None,
data=[0, 0]
args={'width': 100, 'format': '{:,}', 'suffix': '', 'no_labels': False, 'no_values': False, 'vertical': False, 'stacked': False, 'histogram': False, 'different_scale': False},
labels=['iOS', 'Android']
)
ERROR: Problem running script: Traceback (most recent call last):
File "/../main.py", line 523, in <module>
cli_handler()
File "/.../lib/python3.8/site-packages/click/core.py", line 829, in __call__
return self.main(*args, **kwargs)
File "/.../lib/python3.8/site-packages/click/core.py", line 782, in main
rv = self.invoke(ctx)
File "/.../lib/python3.8/site-packages/click/core.py", line 1066, in invoke
return ctx.invoke(self.callback, **ctx.params)
File "/.../lib/python3.8/site-packages/click/core.py", line 610, in invoke
return callback(*args, **kwargs)
File "/../main.py", line 194, in cli_handler
main(
File "/.../main.py", line 449, in main
termgraph.chart(
File "/.../lib/python3.8/site-packages/termgraph/termgraph.py", line 485, in chart
normal_dat = normalize(data, args["width"])
File "/.../lib/python3.8/site-packages/termgraph/termgraph.py", line 162, in normalize
norm_factor = width / float(max_datum)
ZeroDivisionError: float division by zero
Hi, is there any documentation for how to use termgraph within a .py script instead of on the terminal? Was searching for any form of documentation online, and I found the following code which works, thus I was wondering how I could do the same on a .py script for horizontal graphs:
from termgraph import termgraph as tg
labels = ['2007', '2008', '2009', '2010', '2011', '2012', '2014']
data = [[183.32, 190.52], [231.23, 5.0], [16.43, 53.1], [50.21, 7.0], [508.97, 10.45], [212.05, 20.2], [30.0, 20.0]]
normal_data = [[48.059508408796894, 50.0], [60.971862871927556, 0.0],
[3.080530401034929, 12.963561880120743],
[12.184670116429496, 0.5390254420008624],
[135.82632600258734, 1.4688443294523499],
[55.802608883139285, 4.096593359206555],
[6.737818025010781, 4.042690815006468]]
len_categories = 2
args = {'filename': 'data/ex4.dat', 'title': None, 'width': 50,
'format': '{:<5.2f}', 'suffix': '', 'no_labels': True,
'color': None, 'vertical': False, 'stacked': True,
'different_scale': False, 'calendar': False,
'start_dt': None, 'custom_tick': '', 'delim': '',
'verbose': False, 'version': False}
colors = [91, 94]
tg.stacked_graph(labels, data, normal_data, len_categories, args, colors)
Unless you have a license, people can not use this inside of other projects.
It would be cool to have a description/implementation to use your project from other scripts.
Termgraph
looks like an amazing tool and it could be really useful for some ad-hoc investigations.
When looking at the logs and other texts it's often useful to run some-command | sort | uniq -c
which counts unique entries and prints the list of unique values and the number of occurrences. For example:
16 alter
17 create
15 drop
12 insert
8 update
Termgraph
would fit nicely into this use case, like some-command | sort | uniq -c | termgraph
. The issue is that termgraph
always expects the label to go first. Of course in the example above it can be solved with Awk for example (like | awk '{print $2, $1}'
, however first of all it's an extra step (which reduces usability), and also it makes it problematic if the label contains a space.
That said, it would be awesome to have a CLI flag for termgraph
like --values-first
, which would tell termgraph
to read the value in the first column and use the rest of the line as a label.
It would allow termgraph
to be used seamlessly in the example above and also provide extra flexibility in other use cases which can use a similar input format
Hi,
I'm seeing the following error when I try and graph this data vertically using the --vertical
cli flag. If I run it without the vertical flag it works fine.
Data:
12/05/2020,3
13/05/2020,10
14/05/2020,14
15/05/2020,22
16/05/2020,17
17/05/2020,19
18/05/2020,24
Command:
termgraph data.csv --vertical
Error:
Traceback (most recent call last):
File "/Users/james/.local/share/virtualenvs/metrics-aYLqKSM2/bin/termgraph", line 8, in <module>
sys.exit(main())
File "/Users/james/.local/share/virtualenvs/metrics-aYLqKSM2/lib/python3.8/site-packages/termgraph/termgraph.py", line 161, in main
chart(colors, data, args, labels)
File "/Users/james/.local/share/virtualenvs/metrics-aYLqKSM2/lib/python3.8/site-packages/termgraph/termgraph.py", line 424, in chart
vertic = vertically(*row, args=args)
TypeError: vertically() got multiple values for argument 'args'
I'm using Python v3.8.2
and termgraph v0.2.2
.
Let me know if there's any more info I can provide.
Hello!
Do you think it would be possible to also have networks displayed in the terminal with termgraph, a bit like Graphviz is doing?
Best regards
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.