The Args class manages chart configuration options and arguments. It provides a centralized way to control chart appearance, behavior, and formatting.
from termgraph import Args
# Default args
args = Args()
# Custom args
args = Args(
width=60,
title="My Chart",
colors=["red", "blue"],
suffix=" units"
)All parameters are optional and provided as keyword arguments. If not specified, default values are used.
The width of the chart in characters.
args = Args(width=80) # Wide chart
args = Args(width=30) # Narrow chartChart title displayed at the top.
args = Args(title="Monthly Sales Report")List of color codes for chart series. Use color names or ANSI codes.
from termgraph import Colors
args = Args(colors=[Colors.Blue, Colors.Green, Colors.Red])
# Or use color names
args = Args(colors=["blue", "green", "red"])Available color constants:
Colors.BlackColors.RedColors.GreenColors.YellowColors.BlueColors.MagentaColors.Cyan
Custom character to use for chart bars instead of the default block character.
args = Args(custom_tick="*") # Use asterisks
args = Args(custom_tick="=") # Use equals signs
args = Args(custom_tick="█") # Use solid blocksPython format string for numeric values.
args = Args(format="{:<6.1f}") # 6 chars wide, 1 decimal
args = Args(format="{:>8.0f}") # Right-aligned, no decimals
args = Args(format="{:+.2f}") # Always show signText appended to each value.
args = Args(suffix=" units") # Append units
args = Args(suffix="K") # Thousands
args = Args(suffix="$") # CurrencyFormat values as percentages.
# Convert 0.75 to 75%
args = Args(percentage=True)Disable automatic conversion of large numbers to readable format (e.g., 1000 → 1K).
args = Args(no_readable=True) # Show raw numbersHide row labels.
args = Args(no_labels=True) # Hide all labelsHide numeric values next to bars.
args = Args(no_values=True) # Show only barsDisplay labels before the bars instead of to the left with colons.
args = Args(label_before=True)
# Changes "Label: ████" to "Label ████"Add blank lines between chart rows.
args = Args(space_between=True) # More readable spacingCreate vertical/column charts instead of horizontal bars.
args = Args(vertical=True) # Column chartUse different scales for each data series in multi-series charts.
# Useful when series have very different ranges
args = Args(different_scale=True)Create stacked bar charts for multi-series data.
args = Args(stacked=True) # Stack series on top of each otherEnable histogram mode.
args = Args(histogram=True, bins=10)Number of bins for histogram charts.
args = Args(bins=8) # 8 histogram bins
args = Args(bins=15) # Fine-grained histogramInput filename (used by CLI, usually not needed for API usage).
Custom delimiter for data parsing.
Enable calendar heatmap mode.
Start date for calendar charts.
Enable verbose output for debugging.
args = Args(verbose=True) # Show debug informationGet the value of a specific argument.
args = Args(width=60, title="Test")
width = args.get_arg("width") # Returns 60
title = args.get_arg("title") # Returns "Test"Update multiple arguments after initialization.
args = Args(width=50)
args.update_args(width=80, title="Updated Chart")from termgraph import Args, Colors
# Simple configuration
args = Args(
width=50,
title="Sales Data",
colors=[Colors.Blue],
suffix=" units"
)from termgraph import Args
# Detailed formatting options
args = Args(
width=70,
title="Financial Performance Q4 2023",
format="{:>8.2f}", # Right-aligned, 2 decimals
suffix="K USD", # Thousands of dollars
space_between=True, # Better readability
no_readable=True # Show exact numbers
)from termgraph import Args, Colors
# Multi-series with different colors
args = Args(
width=60,
title="Product Comparison",
colors=[Colors.Green, Colors.Blue, Colors.Red],
different_scale=False, # Use same scale
space_between=True
)from termgraph import Args, Colors
# Stacked chart setup
args = Args(
width=50,
title="Market Share Evolution",
colors=[Colors.Blue, Colors.Green, Colors.Yellow],
stacked=True,
format="{:<4.0f}",
suffix="%"
)from termgraph import Args, Colors
# Histogram settings
args = Args(
width=60,
title="Data Distribution",
histogram=True,
bins=10,
colors=[Colors.Cyan],
format="{:<3.0f}"
)from termgraph import Args
# Clean, minimal appearance
args = Args(
width=40,
no_values=True, # Hide numbers
custom_tick="▓", # Custom bar character
colors=["green"]
)from termgraph import Args, Colors
# Percentage display
args = Args(
width=50,
title="Completion Status",
percentage=True,
colors=[Colors.Green],
format="{:<3.0f}",
suffix="%"
)from termgraph import Args, Colors
# Column chart setup
args = Args(
width=30,
title="Vertical Sales Chart",
vertical=True,
colors=[Colors.Blue],
no_labels=False
)# All default values
default_args = {
"filename": "-",
"title": None,
"width": 50,
"format": "{:<5.2f}",
"suffix": "",
"no_labels": False,
"no_values": False,
"space_between": False,
"colors": None,
"vertical": False,
"stacked": False,
"histogram": False,
"bins": 5,
"different_scale": False,
"calendar": False,
"start_dt": None,
"custom_tick": "",
"delim": "",
"verbose": False,
"label_before": False,
"percentage": False,
"no_readable": False,
}The Args class validates argument names:
from termgraph import Args
try:
# Invalid argument name
args = Args(invalid_option=True)
except Exception as e:
print(f"Error: {e}") # "Invalid Argument: invalid_option"
try:
# Invalid argument in get_arg
args = Args()
value = args.get_arg("nonexistent")
except Exception as e:
print(f"Error: {e}") # "Invalid Argument: nonexistent"The Args object is passed to chart constructors:
from termgraph import Data, BarChart, Args, Colors
# Create data and args
data = Data([10, 20, 30], ["A", "B", "C"])
args = Args(
width=40,
title="Sample Chart",
colors=[Colors.Green]
)
# Create and draw chart
chart = BarChart(data, args)
chart.draw()For more information about chart types, see Chart Classes Documentation. For data preparation, see Data Class Documentation.