termatplotlib 0.1.0__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
|
@@ -0,0 +1,370 @@
|
|
|
1
|
+
|
|
2
|
+
import math
|
|
3
|
+
|
|
4
|
+
COLORS = {
|
|
5
|
+
'black': '\033[30m',
|
|
6
|
+
'red': '\033[31m',
|
|
7
|
+
'green': '\033[32m',
|
|
8
|
+
'yellow': '\033[33m',
|
|
9
|
+
'blue': '\033[34m',
|
|
10
|
+
'magenta': '\033[35m',
|
|
11
|
+
'cyan': '\033[36m',
|
|
12
|
+
'white': '\033[37m',
|
|
13
|
+
'reset': '\033[0m'
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
def bar(labels, values, max_width=80, title=None, xlabel=None, ylabel=None, color=None, output_file=None):
|
|
17
|
+
"""
|
|
18
|
+
Displays a horizontal bar chart in the terminal.
|
|
19
|
+
"""
|
|
20
|
+
output = []
|
|
21
|
+
if title:
|
|
22
|
+
output.append(f"\n{title.center(max_width)}\n")
|
|
23
|
+
|
|
24
|
+
if not labels or not values or len(labels) != len(values):
|
|
25
|
+
if output_file:
|
|
26
|
+
with open(output_file, 'w') as f:
|
|
27
|
+
f.write("Error: Invalid input. Labels and values must be non-empty and of the same length.\n")
|
|
28
|
+
else:
|
|
29
|
+
print("Error: Invalid input. Labels and values must be non-empty and of the same length.")
|
|
30
|
+
return
|
|
31
|
+
|
|
32
|
+
max_label_len = max(len(str(label)) for label in labels)
|
|
33
|
+
max_value = max(values)
|
|
34
|
+
scale = (max_width - max_label_len - 5) / max_value
|
|
35
|
+
|
|
36
|
+
color_code = COLORS.get(color, '')
|
|
37
|
+
reset_code = COLORS['reset'] if color_code else ''
|
|
38
|
+
|
|
39
|
+
if ylabel:
|
|
40
|
+
output.append(f"{ylabel.rjust(max_label_len)}")
|
|
41
|
+
|
|
42
|
+
for i, (label, value) in enumerate(zip(labels, values)):
|
|
43
|
+
bar_len = int(value * scale)
|
|
44
|
+
bar = '█' * bar_len
|
|
45
|
+
output.append(f"{str(label):<{max_label_len}} | {color_code}{bar}{reset_code} {value}")
|
|
46
|
+
|
|
47
|
+
if xlabel:
|
|
48
|
+
output.append(f"\n{xlabel.center(max_width)}")
|
|
49
|
+
|
|
50
|
+
if output_file:
|
|
51
|
+
with open(output_file, 'w') as f:
|
|
52
|
+
f.write("\n".join(output) + "\n")
|
|
53
|
+
else:
|
|
54
|
+
print("\n".join(output))
|
|
55
|
+
|
|
56
|
+
|
|
57
|
+
def scatter(data, width=50, height=20, title=None, xlabel=None, ylabel=None, output_file=None, color=None):
|
|
58
|
+
"""
|
|
59
|
+
Displays a scatter plot in the terminal with multiple series.
|
|
60
|
+
data: A list of dictionaries, where each dictionary represents a series
|
|
61
|
+
and contains 'x', 'y', 'color', and 'marker' keys.
|
|
62
|
+
"""
|
|
63
|
+
output = []
|
|
64
|
+
if title:
|
|
65
|
+
output.append(f"\n{title.center(width)}\n")
|
|
66
|
+
|
|
67
|
+
all_x = [val for series in data for val in series['x']]
|
|
68
|
+
all_y = [val for series in data for val in series['y']]
|
|
69
|
+
|
|
70
|
+
if not all_x or not all_y:
|
|
71
|
+
if output_file:
|
|
72
|
+
with open(output_file, 'w') as f:
|
|
73
|
+
f.write("Error: Input data cannot be empty.\n")
|
|
74
|
+
else:
|
|
75
|
+
print("Error: Input data cannot be empty.")
|
|
76
|
+
return
|
|
77
|
+
|
|
78
|
+
min_x, max_x = min(all_x), max(all_x)
|
|
79
|
+
min_y, max_y = min(all_y), max(all_y)
|
|
80
|
+
|
|
81
|
+
x_range = max_x - min_x
|
|
82
|
+
y_range = max_y - min_y
|
|
83
|
+
|
|
84
|
+
grid = [[' ' for _ in range(width)] for _ in range(height)]
|
|
85
|
+
|
|
86
|
+
for series in data:
|
|
87
|
+
x = series['x']
|
|
88
|
+
y = series['y']
|
|
89
|
+
color = series.get('color')
|
|
90
|
+
marker = series.get('marker', '*')
|
|
91
|
+
|
|
92
|
+
color_code = COLORS.get(color, '')
|
|
93
|
+
reset_code = COLORS['reset'] if color_code else ''
|
|
94
|
+
|
|
95
|
+
for i in range(len(x)):
|
|
96
|
+
x_scaled = int(((x[i] - min_x) / x_range) * (width - 1)) if x_range != 0 else 0
|
|
97
|
+
y_scaled = int(((y[i] - min_y) / y_range) * (height - 1)) if y_range != 0 else 0
|
|
98
|
+
grid[height - 1 - y_scaled][x_scaled] = color_code + marker + reset_code
|
|
99
|
+
|
|
100
|
+
# Add y-axis labels
|
|
101
|
+
y_label_width = len(f"{max_y:.1f}") + 2 # Max width for y-axis labels, assuming one decimal place
|
|
102
|
+
|
|
103
|
+
# Create a new grid that includes space for y-axis labels
|
|
104
|
+
display_grid = [[' ' for _ in range(width + y_label_width)] for _ in range(height)]
|
|
105
|
+
|
|
106
|
+
for r in range(height):
|
|
107
|
+
y_val = min_y + (height - 1 - r) * (y_range / (height - 1) if height > 1 else 1)
|
|
108
|
+
if r % (height // 5 if height >= 5 else 1) == 0 or r == 0 or r == height - 1: # Print ~5 ticks and ends
|
|
109
|
+
label = f"{y_val:.1f}"
|
|
110
|
+
for i, char in enumerate(label):
|
|
111
|
+
if i < y_label_width:
|
|
112
|
+
display_grid[r][i] = char
|
|
113
|
+
|
|
114
|
+
# Copy the plot content to the display grid
|
|
115
|
+
for c in range(width):
|
|
116
|
+
display_grid[r][c + y_label_width] = grid[r][c]
|
|
117
|
+
|
|
118
|
+
output.append('+' + '-' * (width + y_label_width) + '+')
|
|
119
|
+
for row in display_grid:
|
|
120
|
+
output.append('|' + ''.join(row) + '|')
|
|
121
|
+
output.append('+' + '-' * (width + y_label_width) + '+')
|
|
122
|
+
|
|
123
|
+
# Add x-axis labels
|
|
124
|
+
x_tick_interval = x_range / (width - 1) if width > 1 else 1
|
|
125
|
+
x_labels_line = [" "] * (width + y_label_width)
|
|
126
|
+
for c in range(width):
|
|
127
|
+
x_val = min_x + c * x_tick_interval
|
|
128
|
+
if c % (width // 5 if width >= 5 else 1) == 0 or c == 0 or c == width - 1: # Print ~5 ticks and ends
|
|
129
|
+
label = f"{x_val:.1f}"
|
|
130
|
+
# Ensure label fits and doesn't overwrite other labels
|
|
131
|
+
if c + y_label_width + len(label) < len(x_labels_line):
|
|
132
|
+
for i, char in enumerate(label):
|
|
133
|
+
x_labels_line[c + y_label_width + i] = char
|
|
134
|
+
output.append(''.join(x_labels_line))
|
|
135
|
+
|
|
136
|
+
if xlabel:
|
|
137
|
+
output.append(f"\n{xlabel.center(width + y_label_width)}")
|
|
138
|
+
output.append("\n")
|
|
139
|
+
|
|
140
|
+
if output_file:
|
|
141
|
+
with open(output_file, 'w') as f:
|
|
142
|
+
f.write("\n".join(output) + "\n")
|
|
143
|
+
else:
|
|
144
|
+
print("\n".join(output))
|
|
145
|
+
|
|
146
|
+
|
|
147
|
+
def line(data, width=50, height=20, title=None, xlabel=None, ylabel=None, output_file=None, color=None):
|
|
148
|
+
"""
|
|
149
|
+
Displays a line chart in the terminal with multiple series.
|
|
150
|
+
data: A list of dictionaries, where each dictionary represents a series
|
|
151
|
+
and contains 'x', 'y', 'color', and 'marker' keys.
|
|
152
|
+
"""
|
|
153
|
+
output = []
|
|
154
|
+
if title:
|
|
155
|
+
output.append(f"\n{title.center(width)}\n")
|
|
156
|
+
|
|
157
|
+
all_x = [val for series in data for val in series['x']]
|
|
158
|
+
all_y = [val for series in data for val in series['y']]
|
|
159
|
+
|
|
160
|
+
if not all_x or not all_y:
|
|
161
|
+
if output_file:
|
|
162
|
+
with open(output_file, 'w') as f:
|
|
163
|
+
f.write("Error: Input data cannot be empty.\n")
|
|
164
|
+
else:
|
|
165
|
+
print("Error: Input data cannot be empty.")
|
|
166
|
+
return
|
|
167
|
+
|
|
168
|
+
min_x, max_x = min(all_x), max(all_x)
|
|
169
|
+
min_y, max_y = min(all_y), max(all_y)
|
|
170
|
+
|
|
171
|
+
x_range = max_x - min_x
|
|
172
|
+
y_range = max_y - min_y
|
|
173
|
+
|
|
174
|
+
grid = [[' ' for _ in range(width)] for _ in range(height)]
|
|
175
|
+
|
|
176
|
+
for series in data:
|
|
177
|
+
x = series['x']
|
|
178
|
+
y = series['y']
|
|
179
|
+
color = series.get('color')
|
|
180
|
+
marker = series.get('marker', '*')
|
|
181
|
+
|
|
182
|
+
color_code = COLORS.get(color, '')
|
|
183
|
+
reset_code = COLORS['reset'] if color_code else ''
|
|
184
|
+
|
|
185
|
+
def plot_line(x0, y0, x1, y1):
|
|
186
|
+
dx = abs(x1 - x0)
|
|
187
|
+
dy = -abs(y1 - y0)
|
|
188
|
+
sx = 1 if x0 < x1 else -1
|
|
189
|
+
sy = 1 if y0 < y1 else -1
|
|
190
|
+
err = dx + dy
|
|
191
|
+
|
|
192
|
+
while True:
|
|
193
|
+
if 0 <= y0 < height and 0 <= x0 < width:
|
|
194
|
+
grid[y0][x0] = color_code + marker + reset_code
|
|
195
|
+
if x0 == x1 and y0 == y1:
|
|
196
|
+
break
|
|
197
|
+
e2 = 2 * err
|
|
198
|
+
if e2 >= dy:
|
|
199
|
+
err += dy
|
|
200
|
+
x0 += sx
|
|
201
|
+
if e2 <= dx:
|
|
202
|
+
err += dx
|
|
203
|
+
y0 += sy
|
|
204
|
+
|
|
205
|
+
scaled_points = []
|
|
206
|
+
for i in range(len(x)):
|
|
207
|
+
x_scaled = int(((x[i] - min_x) / x_range) * (width - 1)) if x_range != 0 else 0
|
|
208
|
+
y_scaled = int(((y[i] - min_y) / y_range) * (height - 1)) if y_range != 0 else 0
|
|
209
|
+
scaled_points.append((x_scaled, height - 1 - y_scaled))
|
|
210
|
+
|
|
211
|
+
for i in range(len(scaled_points) - 1):
|
|
212
|
+
plot_line(scaled_points[i][0], scaled_points[i][1], scaled_points[i+1][0], scaled_points[i+1][1])
|
|
213
|
+
|
|
214
|
+
# Add y-axis labels
|
|
215
|
+
y_label_width = len(f"{max_y:.1f}") + 2 # Max width for y-axis labels, assuming one decimal place
|
|
216
|
+
|
|
217
|
+
# Create a new grid that includes space for y-axis labels
|
|
218
|
+
display_grid = [[' ' for _ in range(width + y_label_width)] for _ in range(height)]
|
|
219
|
+
|
|
220
|
+
for r in range(height):
|
|
221
|
+
y_val = min_y + (height - 1 - r) * (y_range / (height - 1) if height > 1 else 1)
|
|
222
|
+
if r % (height // 5 if height >= 5 else 1) == 0 or r == 0 or r == height - 1: # Print ~5 ticks and ends
|
|
223
|
+
label = f"{y_val:.1f}"
|
|
224
|
+
for i, char in enumerate(label):
|
|
225
|
+
if i < y_label_width:
|
|
226
|
+
display_grid[r][i] = char
|
|
227
|
+
|
|
228
|
+
# Copy the plot content to the display grid
|
|
229
|
+
for c in range(width):
|
|
230
|
+
display_grid[r][c + y_label_width] = grid[r][c]
|
|
231
|
+
|
|
232
|
+
output.append('+' + '-' * (width + y_label_width) + '+')
|
|
233
|
+
for row in display_grid:
|
|
234
|
+
output.append('|' + ''.join(row) + '|')
|
|
235
|
+
output.append('+' + '-' * (width + y_label_width) + '+')
|
|
236
|
+
|
|
237
|
+
# Add x-axis labels
|
|
238
|
+
x_tick_interval = x_range / (width - 1) if width > 1 else 1
|
|
239
|
+
x_labels_line = [" "] * (width + y_label_width)
|
|
240
|
+
for c in range(width):
|
|
241
|
+
x_val = min_x + c * x_tick_interval
|
|
242
|
+
if c % (width // 5 if width >= 5 else 1) == 0 or c == 0 or c == width - 1: # Print ~5 ticks and ends
|
|
243
|
+
label = f"{x_val:.1f}"
|
|
244
|
+
# Ensure label fits and doesn't overwrite other labels
|
|
245
|
+
if c + y_label_width + len(label) < len(x_labels_line):
|
|
246
|
+
for i, char in enumerate(label):
|
|
247
|
+
x_labels_line[c + y_label_width + i] = char
|
|
248
|
+
output.append(''.join(x_labels_line))
|
|
249
|
+
|
|
250
|
+
if xlabel:
|
|
251
|
+
output.append(f"\n{xlabel.center(width + y_label_width)}")
|
|
252
|
+
output.append("\n")
|
|
253
|
+
|
|
254
|
+
if output_file:
|
|
255
|
+
with open(output_file, 'w') as f:
|
|
256
|
+
f.write("\n".join(output) + "\n")
|
|
257
|
+
else:
|
|
258
|
+
print("\n".join(output))
|
|
259
|
+
|
|
260
|
+
def pie(labels, values, radius=10, title=None, legend=True):
|
|
261
|
+
"""
|
|
262
|
+
Displays a pie chart in the terminal.
|
|
263
|
+
"""
|
|
264
|
+
if title:
|
|
265
|
+
print(f"\n{title.center(radius * 2)}\n")
|
|
266
|
+
|
|
267
|
+
if not labels or not values or len(labels) != len(values):
|
|
268
|
+
print("Error: Invalid input. Labels and values must be non-empty and of the same length.")
|
|
269
|
+
return
|
|
270
|
+
|
|
271
|
+
total = sum(values)
|
|
272
|
+
proportions = [v / total for v in values]
|
|
273
|
+
colors = list(COLORS.keys())[:-1] # Exclude 'reset'
|
|
274
|
+
|
|
275
|
+
grid = [[' ' for _ in range(radius * 2)] for _ in range(radius * 2)]
|
|
276
|
+
center_x, center_y = radius, radius
|
|
277
|
+
|
|
278
|
+
start_angle = 0
|
|
279
|
+
for i, prop in enumerate(proportions):
|
|
280
|
+
end_angle = start_angle + prop * 2 * math.pi
|
|
281
|
+
color = COLORS[colors[i % len(colors)]]
|
|
282
|
+
|
|
283
|
+
for y in range(radius * 2):
|
|
284
|
+
for x in range(radius * 2):
|
|
285
|
+
dx, dy = x - center_x, y - center_y
|
|
286
|
+
angle = math.atan2(dy, dx)
|
|
287
|
+
if angle < 0:
|
|
288
|
+
angle += 2 * math.pi
|
|
289
|
+
|
|
290
|
+
if dx**2 + dy**2 <= radius**2:
|
|
291
|
+
if start_angle <= angle < end_angle:
|
|
292
|
+
grid[y][x] = color + '█' + COLORS['reset']
|
|
293
|
+
|
|
294
|
+
start_angle = end_angle
|
|
295
|
+
|
|
296
|
+
for row in grid:
|
|
297
|
+
print(''.join(row))
|
|
298
|
+
|
|
299
|
+
if legend:
|
|
300
|
+
print("\nLegend:")
|
|
301
|
+
for i, label in enumerate(labels):
|
|
302
|
+
color = COLORS[colors[i % len(colors)]]
|
|
303
|
+
print(f"{color}█{COLORS['reset']} {label}: {values[i]} ({proportions[i]:.1%})")
|
|
304
|
+
print("\n")
|
|
305
|
+
|
|
306
|
+
|
|
307
|
+
def hist(data, bins=10, width=80, height=10, title=None, xlabel=None, ylabel=None, color=None, char='█'):
|
|
308
|
+
"""
|
|
309
|
+
Displays a histogram in the terminal.
|
|
310
|
+
"""
|
|
311
|
+
if title:
|
|
312
|
+
print(f"\n{title.center(width)}\n")
|
|
313
|
+
|
|
314
|
+
if not data:
|
|
315
|
+
print("Error: Input data cannot be empty.")
|
|
316
|
+
return
|
|
317
|
+
|
|
318
|
+
min_val, max_val = min(data), max(data)
|
|
319
|
+
if min_val == max_val:
|
|
320
|
+
print("Error: All data points are the same, cannot create meaningful bins.")
|
|
321
|
+
return
|
|
322
|
+
|
|
323
|
+
bin_range = (max_val - min_val) / bins
|
|
324
|
+
counts = [0] * bins
|
|
325
|
+
bin_edges = [min_val + i * bin_range for i in range(bins + 1)]
|
|
326
|
+
|
|
327
|
+
for x in data:
|
|
328
|
+
if x == max_val: # Include max_val in the last bin
|
|
329
|
+
counts[bins - 1] += 1
|
|
330
|
+
else:
|
|
331
|
+
for i in range(bins):
|
|
332
|
+
if bin_edges[i] <= x < bin_edges[i+1]:
|
|
333
|
+
counts[i] += 1
|
|
334
|
+
break
|
|
335
|
+
|
|
336
|
+
max_count = max(counts)
|
|
337
|
+
if max_count == 0:
|
|
338
|
+
print("No data points fell into any bin.")
|
|
339
|
+
return
|
|
340
|
+
|
|
341
|
+
scale = height / max_count
|
|
342
|
+
|
|
343
|
+
color_code = COLORS.get(color, '')
|
|
344
|
+
reset_code = COLORS['reset'] if color_code else ''
|
|
345
|
+
|
|
346
|
+
# Print the histogram bars
|
|
347
|
+
for h in range(height - 1, -1, -1):
|
|
348
|
+
row_str = ""
|
|
349
|
+
for i in range(bins):
|
|
350
|
+
if counts[i] * scale > h:
|
|
351
|
+
row_str += color_code + char + reset_code + " " * (width // bins - 1)
|
|
352
|
+
else:
|
|
353
|
+
row_str += " " * (width // bins)
|
|
354
|
+
print(row_str)
|
|
355
|
+
|
|
356
|
+
# Print x-axis labels (bin edges)
|
|
357
|
+
print("-" * width)
|
|
358
|
+
bin_labels = [f"{edge:.1f}" for edge in bin_edges]
|
|
359
|
+
label_spacing = width // bins
|
|
360
|
+
label_line = ""
|
|
361
|
+
for i in range(bins):
|
|
362
|
+
label = bin_labels[i]
|
|
363
|
+
label_line += label.ljust(label_spacing)[:label_spacing]
|
|
364
|
+
print(label_line)
|
|
365
|
+
|
|
366
|
+
if xlabel:
|
|
367
|
+
print(f"\n{xlabel.center(width)}")
|
|
368
|
+
if ylabel:
|
|
369
|
+
print(f"{ylabel.rjust(10)} (count)")
|
|
370
|
+
print("\n")
|
|
@@ -0,0 +1,139 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: termatplotlib
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Summary: A lightweight and elegant Python library for rendering stunning ASCII plots directly in your terminal. Visualize your data with beautiful scatter, line, and bar charts, bringing the power of matplotlib to your command line.
|
|
5
|
+
Home-page: https://github.com/rkstudio585/termatplotlib
|
|
6
|
+
Author: RK RIAD & RK STUDIO 585
|
|
7
|
+
Author-email: rkstudio585@github.com
|
|
8
|
+
Classifier: Programming Language :: Python :: 3
|
|
9
|
+
Classifier: License :: OSI Approved :: MIT License
|
|
10
|
+
Classifier: Operating System :: OS Independent
|
|
11
|
+
Requires-Python: >=3.6
|
|
12
|
+
Description-Content-Type: text/markdown
|
|
13
|
+
License-File: LICENSE
|
|
14
|
+
Dynamic: author
|
|
15
|
+
Dynamic: author-email
|
|
16
|
+
Dynamic: classifier
|
|
17
|
+
Dynamic: description
|
|
18
|
+
Dynamic: description-content-type
|
|
19
|
+
Dynamic: home-page
|
|
20
|
+
Dynamic: license-file
|
|
21
|
+
Dynamic: requires-python
|
|
22
|
+
Dynamic: summary
|
|
23
|
+
|
|
24
|
+
# termatplotlib
|
|
25
|
+
|
|
26
|
+
A lightweight and elegant Python library for rendering stunning ASCII plots directly in your terminal. Visualize your data with beautiful scatter, line, and bar charts, bringing the power of matplotlib to your command line.
|
|
27
|
+
|
|
28
|
+
## Features
|
|
29
|
+
|
|
30
|
+
* **Terminal-based Visualization:** Generate plots directly in your terminal using ASCII characters.
|
|
31
|
+
* **Multiple Chart Types:** Supports bar charts, scatter plots, line charts, pie charts, and histograms.
|
|
32
|
+
* **Customization:** Options for titles, axis labels, colors, and markers.
|
|
33
|
+
* **File Output:** Save your terminal plots to text files for sharing or later review.
|
|
34
|
+
* **Easy to Use:** Simple API designed for quick and intuitive plotting.
|
|
35
|
+
|
|
36
|
+
## Installation
|
|
37
|
+
|
|
38
|
+
It is recommended to install `termatplotlib` using `pip` within a virtual environment.
|
|
39
|
+
|
|
40
|
+
```bash
|
|
41
|
+
# Create a virtual environment
|
|
42
|
+
python -m venv venv
|
|
43
|
+
|
|
44
|
+
# Activate the virtual environment
|
|
45
|
+
# On Linux/macOS:
|
|
46
|
+
source venv/bin/activate
|
|
47
|
+
# On Windows:
|
|
48
|
+
# .\venv\Scripts\activate
|
|
49
|
+
|
|
50
|
+
# Install termatplotlib
|
|
51
|
+
pip install termatplotlib
|
|
52
|
+
```
|
|
53
|
+
|
|
54
|
+
Alternatively, if you have cloned the repository, you can install it from the source:
|
|
55
|
+
|
|
56
|
+
```bash
|
|
57
|
+
pip install .
|
|
58
|
+
```
|
|
59
|
+
|
|
60
|
+
## Usage
|
|
61
|
+
|
|
62
|
+
`termatplotlib` provides a simple API to create various types of plots.
|
|
63
|
+
|
|
64
|
+
### Bar Chart
|
|
65
|
+
|
|
66
|
+
```python
|
|
67
|
+
import termatplotlib as tpl
|
|
68
|
+
|
|
69
|
+
print("--- Example: Bar Chart ---")
|
|
70
|
+
labels = ["A", "B", "C", "D"]
|
|
71
|
+
values = [10, 20, 15, 5]
|
|
72
|
+
tpl.bar(labels, values, title="My Bar Chart", xlabel="Value", ylabel="Category", color="red")
|
|
73
|
+
```
|
|
74
|
+
|
|
75
|
+
### Scatter Plot
|
|
76
|
+
|
|
77
|
+
```python
|
|
78
|
+
import termatplotlib as tpl
|
|
79
|
+
|
|
80
|
+
print("--- Example: Scatter Plot ---")
|
|
81
|
+
x = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
|
|
82
|
+
y = [2, 4, 5, 7, 6, 8, 9, 10, 8, 9]
|
|
83
|
+
data_scatter = [{'x': x, 'y': y, 'color': 'blue', 'marker': 'x'}]
|
|
84
|
+
tpl.scatter(data_scatter, title="My Scatter Plot", xlabel="X-Axis", ylabel="Y-Axis")
|
|
85
|
+
```
|
|
86
|
+
|
|
87
|
+
### Line Chart
|
|
88
|
+
|
|
89
|
+
```python
|
|
90
|
+
import termatplotlib as tpl
|
|
91
|
+
|
|
92
|
+
print("--- Example: Line Chart ---")
|
|
93
|
+
x_line = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
|
|
94
|
+
y_line = [0, 1, 4, 9, 16, 25, 36, 49, 64, 81, 100]
|
|
95
|
+
data_line = [{'x': x_line, 'y': y_line, 'color': 'green', 'marker': 'o'}]
|
|
96
|
+
tpl.line(data_line, title="My Line Chart", xlabel="X-Axis", ylabel="Y-Axis")
|
|
97
|
+
```
|
|
98
|
+
|
|
99
|
+
### Pie Chart
|
|
100
|
+
|
|
101
|
+
```python
|
|
102
|
+
import termatplotlib as tpl
|
|
103
|
+
|
|
104
|
+
print("--- Example: Pie Chart ---")
|
|
105
|
+
labels = ["A", "B", "C", "D"]
|
|
106
|
+
values = [10, 20, 15, 5]
|
|
107
|
+
tpl.pie(labels, values, title="My Pie Chart")
|
|
108
|
+
```
|
|
109
|
+
|
|
110
|
+
### Histogram
|
|
111
|
+
|
|
112
|
+
```python
|
|
113
|
+
import termatplotlib as tpl
|
|
114
|
+
|
|
115
|
+
print("--- Example: Histogram ---")
|
|
116
|
+
data_hist = [1, 1, 2, 3, 3, 3, 4, 5, 5, 6, 7, 7, 7, 7, 8, 9, 10]
|
|
117
|
+
tpl.hist(data_hist, bins=5, title="My Histogram", xlabel="Value Range", ylabel="Frequency", color="magenta")
|
|
118
|
+
```
|
|
119
|
+
|
|
120
|
+
### Saving to File
|
|
121
|
+
|
|
122
|
+
You can save any chart to a text file by providing the `output_file` argument (where supported).
|
|
123
|
+
|
|
124
|
+
```python
|
|
125
|
+
import termatplotlib as tpl
|
|
126
|
+
|
|
127
|
+
# Example: Bar chart saved to file
|
|
128
|
+
labels = ["E", "F", "G"]
|
|
129
|
+
values = [25, 10, 30]
|
|
130
|
+
tpl.bar(labels, values, title="Another Bar Chart", color="blue", output_file="bar_chart.txt")
|
|
131
|
+
```
|
|
132
|
+
|
|
133
|
+
## Contributing
|
|
134
|
+
|
|
135
|
+
Contributions are welcome! Please feel free to open issues or submit pull requests on the [GitHub repository](https://github.com/rkstudio585/termatplotlib).
|
|
136
|
+
|
|
137
|
+
## License
|
|
138
|
+
|
|
139
|
+
This project is licensed under the MIT License - see the [LICENSE](LICENSE) file for details.
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
termatplotlib/__init__.py,sha256=-GF-UIFBhSLBRs_x5w-6isNmYEu9j5XmcmnRlwRi65k,12841
|
|
2
|
+
termatplotlib-0.1.0.dist-info/licenses/LICENSE,sha256=VGAYHbZgFPrS10C3mVeces6AskkMK7dTWxuyOqGnw_Y,1079
|
|
3
|
+
termatplotlib-0.1.0.dist-info/METADATA,sha256=J1YxyiObA_kRPwNC_b09EhG7bM01fNHk00d_xNAZFWw,4081
|
|
4
|
+
termatplotlib-0.1.0.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
|
|
5
|
+
termatplotlib-0.1.0.dist-info/top_level.txt,sha256=ei92aYXPDqNYPUb-H5uI5i2VZ9QOkdfA6z9Xc4aXzbM,14
|
|
6
|
+
termatplotlib-0.1.0.dist-info/RECORD,,
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2025 RK RIAD & RK STUDIO 585
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
termatplotlib
|