-
Notifications
You must be signed in to change notification settings - Fork 165
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[FR] API for python scripts #27
Comments
ugly and hacky work around import sys
import tempfile
from termgraph import termgraph
def plot(data):
with tempfile.NamedTemporaryFile(mode='a+') as f:
# Save data in temporary file
for row in data:
f.write('\t'.join(map(str, row)) + '\n')
# Move cursor in order to make sure that script will
# start reading file from the beggining.
f.seek(0)
# Overwrite args in case if there were some other
# arguments passed to the main script
#
# Additional arguments can be passed in the same way.
original_argv = sys.argv
sys.argv = [sys.argv[0], f.name]
termgraph.main()
# Revert back changes to the original arguemnts
sys.argv = original_argv
plot([['a', 3], ['b', 8], ['c', 6]])
|
this is snippet for example 1 >>> labels = ['2007', '2008', '2009', '2010', '2011', '2012', '2014']
>>> data = [[183.32], [231.23], [16.43], [50.21], [508.97], [212.05], [1.0]]
>>> args = {
>>> 'stacked': False, 'width': 50, 'no_labels': False, 'format': '{:<5.2f}',
>>> 'suffix': '', "vertical": False
>>> }
>>> from termgraph.termgraph import chart
>>> chart(colors=[], data=data, args=args, labels=labels) |
how can i make a Multi-variable ? |
can you elaborate more @songmuyi? |
Needed a modification from code above, added few param, got exceptions without them. labels = ["2007", "2008", "2009", "2010", "2011", "2012", "2013"]
data = [[183.32], [231.23], [16.43], [50.21], [508.97], [212.05], [1.0]]
args = {
"stacked": False,
"width": 50,
"no_labels": False,
"format": "{:<5.2f}",
"suffix": "",
"vertical": False,
"histogram": False,
"no_values": False,
}
from termgraph.termgraph import chart
chart(colors=[], data=data, args=args, labels=labels) |
Here is a function, FWIW: def tprint(labels, values, **kwargs):
from termgraph.termgraph import chart
args = {
"stacked": False,
"width": 50,
"no_labels": False,
"format": "{:<5.2f}",
"suffix": "",
"vertical": False,
"histogram": False,
"no_values": False,
}
args.update(kwargs)
data = [[x] for x in values]
chart(colors=[], data=data, args=args, labels=labels) You can update default args like this: labels = ["2007", "2008", "2009", "2010", "2011", "2012", "2013"]
values = [183.32, 231.23, 16.43, 50.21, 508.97, 212.05, 1.0]
tprint(labels, values, format="{:<5.0f}") |
epogrebnyak
added a commit
to epogrebnyak/facebook-json-to-csv
that referenced
this issue
Aug 4, 2020
As described in mkaz/termgraph#27
How can I use this for 2 Categories? |
Closed
How to define a color in this case. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
It would be cool to have a description/implementation to use your project from other scripts.
The text was updated successfully, but these errors were encountered: