Open eruvanos opened 6 years ago
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]])
a: ▇▇▇ 3.00
b: ▇▇▇▇▇▇▇▇ 8.00
c: ▇▇▇▇▇▇ 6.00
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?
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)
Needed a modification from code above, added few param, got exceptions without them. Here is a working code:
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}")
How can I use this for 2 Categories?
How to define a color in this case.
It would be cool to have a description/implementation to use your project from other scripts.