itrm 0.2.2__tar.gz → 1.0.0__tar.gz
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.
- itrm-1.0.0/PKG-INFO +305 -0
- itrm-1.0.0/README.md +290 -0
- {itrm-0.2.2 → itrm-1.0.0}/setup.cfg +1 -1
- itrm-1.0.0/src/itrm/itrm.py +3597 -0
- itrm-1.0.0/src/itrm.egg-info/PKG-INFO +305 -0
- itrm-0.2.2/PKG-INFO +0 -320
- itrm-0.2.2/README.md +0 -305
- itrm-0.2.2/src/itrm/itrm.py +0 -1971
- itrm-0.2.2/src/itrm.egg-info/PKG-INFO +0 -320
- {itrm-0.2.2 → itrm-1.0.0}/LICENSE.txt +0 -0
- {itrm-0.2.2 → itrm-1.0.0}/pyproject.toml +0 -0
- {itrm-0.2.2 → itrm-1.0.0}/src/itrm/__init__.py +0 -0
- {itrm-0.2.2 → itrm-1.0.0}/src/itrm.egg-info/SOURCES.txt +0 -0
- {itrm-0.2.2 → itrm-1.0.0}/src/itrm.egg-info/dependency_links.txt +0 -0
- {itrm-0.2.2 → itrm-1.0.0}/src/itrm.egg-info/requires.txt +0 -0
- {itrm-0.2.2 → itrm-1.0.0}/src/itrm.egg-info/top_level.txt +0 -0
itrm-1.0.0/PKG-INFO
ADDED
|
@@ -0,0 +1,305 @@
|
|
|
1
|
+
Metadata-Version: 2.1
|
|
2
|
+
Name: itrm
|
|
3
|
+
Version: 1.0.0
|
|
4
|
+
Summary: Interactive Terminal Utilities
|
|
5
|
+
Home-page: https://gitlab.com/davidwoodburn/itrm
|
|
6
|
+
Author: David Woodburn
|
|
7
|
+
Author-email: david.woodburn@icloud.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.txt
|
|
14
|
+
Requires-Dist: numpy
|
|
15
|
+
|
|
16
|
+
# Interactive Terminal Utilities
|
|
17
|
+
|
|
18
|
+
```python
|
|
19
|
+
import itrm
|
|
20
|
+
```
|
|
21
|
+
|
|
22
|
+
This library offers several functions for visualizing data within the terminal.
|
|
23
|
+
This project does not exist just because it is cool. It exists because it fills
|
|
24
|
+
some needs which few other tools do. For many developers, engineers, and
|
|
25
|
+
scientists, the terminal is where much of their time is spent. Having to switch
|
|
26
|
+
contexts every time a plot is generated can be time consuming and annoying.
|
|
27
|
+
Furthermore, most plotting tools have fairly limited analysis capabilities. They
|
|
28
|
+
are great for generating final, beautiful figures, but not great at quickly
|
|
29
|
+
inspecting and understanding the data. Also, if you are working with a remote
|
|
30
|
+
server through SSH, visualizing the data with conventional tools can be very
|
|
31
|
+
tedious: save data to file, transfer data to local machine, write script just to
|
|
32
|
+
read and plot data, plot data, repeat. This library lets you directly visualize
|
|
33
|
+
and interact with the data, skipping all the tedium.
|
|
34
|
+
|
|
35
|
+
## Configuration
|
|
36
|
+
|
|
37
|
+
This library will generate a `config.ini` file in the same directory as the
|
|
38
|
+
library's installation. You can either manually modify the settings in that
|
|
39
|
+
file, or you can call the `itrm.config()` function. This function will take the
|
|
40
|
+
following parameters:
|
|
41
|
+
|
|
42
|
+
| Setting | Default | Description |
|
|
43
|
+
| --------- | :-----------: | --------------------------------- |
|
|
44
|
+
| `uni` | `True` | flag to use Unicode characters |
|
|
45
|
+
| `cols` | `60` | default column width |
|
|
46
|
+
| `rows` | `20` | default row height |
|
|
47
|
+
| `ar` | `0.48` | aspect ratio of characters |
|
|
48
|
+
| `cmap` | `spectrum` | color map |
|
|
49
|
+
|
|
50
|
+
### Unicode
|
|
51
|
+
|
|
52
|
+
Much of the plotting in the terminal performed by `itrm` relies on Unicode
|
|
53
|
+
characters. However, properly displaying those characters requires having a
|
|
54
|
+
monospace font with those specific glyphs defined. In fact, the default plotting
|
|
55
|
+
mode relies on braille characters, and relatively few fonts define those. If you
|
|
56
|
+
are looking for a good terminal font which supports all the Unicode used by this
|
|
57
|
+
library, try out [JuliaMono][julia]. However, you might not be interested in
|
|
58
|
+
downloading fonts, so this library can also forego all Unicode characters and
|
|
59
|
+
only rely on ASCII characters.
|
|
60
|
+
|
|
61
|
+
### Columns and Rows
|
|
62
|
+
|
|
63
|
+
Many terminals provide a means for a Python script to query the current size of
|
|
64
|
+
the terminal window in terms of the number of columns and rows of text. However,
|
|
65
|
+
not all terminals do. In those cases, it is good to have a fallback setting.
|
|
66
|
+
These are defined by the `cols` and `rows` configuration parameters.
|
|
67
|
+
|
|
68
|
+
### Aspect Ratio
|
|
69
|
+
|
|
70
|
+
Because all the plotting by this library uses text, the aspect ratio (ratio of
|
|
71
|
+
width to height) of the characters affects the apparent aspect ratio of curves.
|
|
72
|
+
So, a circle might look perfectly round or squashed depending on the font
|
|
73
|
+
chosen. This does not mean you need a new font, you just need to adjust the
|
|
74
|
+
aspect ratio setting, `ar`.
|
|
75
|
+
|
|
76
|
+
### Color Map
|
|
77
|
+
|
|
78
|
+
By default, the color map used is `spectrum`, a rainbow of colors. Using the
|
|
79
|
+
`cmap` parameter, you can pick any of the following color maps: `spectrum`,
|
|
80
|
+
`viridis`, `grays`, `reds`, `greens`, `blues`, or `4bit`. All but the last color
|
|
81
|
+
map use platform-independent, 8-bit colors. The last color map, `4bit`, lets use
|
|
82
|
+
control the colors with your terminal settings, instead.
|
|
83
|
+
|
|
84
|
+
## Interactive Plots
|
|
85
|
+
|
|
86
|
+
```python
|
|
87
|
+
itrm.iplot(x, y=None, label=None, rows=1, cols=1,
|
|
88
|
+
lg=None, overlay=False):
|
|
89
|
+
```
|
|
90
|
+
|
|
91
|
+
### Parameters
|
|
92
|
+
|
|
93
|
+
The `iplot` function will render all the data points defined by `x` and `y` to
|
|
94
|
+
the terminal. The inputs `x` and `y` can be vectors, matrices, or lists of such
|
|
95
|
+
arrays. Each **row** of a matrix is treated as a separate curve. Note, this is
|
|
96
|
+
different from MatPlotLib, in which each *column* is treated as a separate row.
|
|
97
|
+
(This difference is intentional, as in the author's opinion varying time along
|
|
98
|
+
columns means each column in a matrix can be treated as a vector. This
|
|
99
|
+
arrangement works very well with in linear algebra, especially matrix
|
|
100
|
+
multiplication with a "set" of vectors over time.)
|
|
101
|
+
|
|
102
|
+
The shapes of `x` and `y` do not have to be the same, but they must be
|
|
103
|
+
compatible. So, `x` could be a vector and `y` could be a matrix as long as the
|
|
104
|
+
length of `x` equals the number of columns of `y`.
|
|
105
|
+
|
|
106
|
+
If only `x` is given, it will be interpreted as the `y` values, and the `x`
|
|
107
|
+
values will be the array of indices.
|
|
108
|
+
|
|
109
|
+
When the plot is printed, the graph is rendered within a box and the ranges of
|
|
110
|
+
`x` and `y` are listed in the bottom left corner. So,
|
|
111
|
+
|
|
112
|
+
```
|
|
113
|
+
(0:99, -1.5:1.5)
|
|
114
|
+
```
|
|
115
|
+
|
|
116
|
+
means that `x` ranges from `0` to `99` and `y` ranges from `-1.5` to `1.5`.
|
|
117
|
+
|
|
118
|
+
If a `label` is given, this will be printed in the bottom right of the plot box.
|
|
119
|
+
It can also be a list of strings. If the length of the list is the same as the
|
|
120
|
+
number of data sets (each row of a matrix is a different data set), then each
|
|
121
|
+
string in the list will be displayed with the respective data set. If the length
|
|
122
|
+
of the list is one greater, the first string will be displayed for the whole
|
|
123
|
+
plot.
|
|
124
|
+
|
|
125
|
+
The `rows` and `cols` parameters let you specify the number of terminal text
|
|
126
|
+
rows and columns to use for the plot, respectively. For each of these, if the
|
|
127
|
+
value is less than or equal to 1, it represents a portion of the available space
|
|
128
|
+
to use. For example, if `rows` is `0.5`, then half the number of rows of the
|
|
129
|
+
current terminal window will be used for the plot. If the value is greater than
|
|
130
|
+
1, it represents the absolute number of rows or columns to use. Also, if the
|
|
131
|
+
size of the current terminal cannot be obtained, the available space will
|
|
132
|
+
default to `20` rows and `60` columns.
|
|
133
|
+
|
|
134
|
+
You can set the x or y axes to logarithmic scaling by setting the `lg` parameter
|
|
135
|
+
to one of `"x"`, `"y"`, or `"xy"`. Note that the values reported for the view
|
|
136
|
+
and the cursor will be in the original scaling, not logarithmic.
|
|
137
|
+
|
|
138
|
+
To prevent your terminal history from extending each time a new plot is
|
|
139
|
+
rendered, you can print a new plot over a previous plot by setting the `overlay`
|
|
140
|
+
parameter to `True`. This can be especially useful when there are multiple plots
|
|
141
|
+
to render (like for an animation) but you do not want your terminal history to
|
|
142
|
+
fill up quickly.
|
|
143
|
+
|
|
144
|
+
### Keybindings
|
|
145
|
+
|
|
146
|
+
The `iplot` function provides interactivity through a vertical cursor. You can
|
|
147
|
+
move the cursor left and right, at normal speed or fast speed. You can zoom in
|
|
148
|
+
and out. And, you can cycle through which rows of the `x` and `y` data to focus
|
|
149
|
+
on. Note, `iplot` is designed for monotonically-increasing `x` values, and,
|
|
150
|
+
consequently, does not support equal axis scaling.
|
|
151
|
+
|
|
152
|
+

|
|
153
|
+
|
|
154
|
+
The following table details the shortcut keys:
|
|
155
|
+
|
|
156
|
+
| Keys | Function | | Keys | Function |
|
|
157
|
+
| :------------: | ---------------------- | - | :------------: | ------------------------ |
|
|
158
|
+
| `q`, `⌫`, `↵` | exit interactive plot | | `j`, `s`, `↓` | zoom in |
|
|
159
|
+
| `h`, `a`, `←` | move cursor left | | `k`, `w`, `↑` | zoom out |
|
|
160
|
+
| `l`, `d`, `→` | move cursor right | | `J`, `S`, `⇧↓` | zoom in fast |
|
|
161
|
+
| `H`, `A`, `⇧←` | move cursor left fast | | `K`, `W`, `⇧↑` | zoom out fast |
|
|
162
|
+
| `L`, `D`, `⇧→` | move cursor right fast | | `n` | select next data set |
|
|
163
|
+
| `g` | move cursor to start | | `N` | select previous data set |
|
|
164
|
+
| `G` | move cursor to end | | `i` | toggle individual view |
|
|
165
|
+
| `c`, `z` | center view on cursor | | `v` | toggle ghost cursor |
|
|
166
|
+
| `x` | toggle x log scaling | | `f` | start function |
|
|
167
|
+
| `y` | toggle y log scaling | | `F` | restore original data |
|
|
168
|
+
|
|
169
|
+
### Individual Data Sets
|
|
170
|
+
|
|
171
|
+
When many data sets are being plotted simultaneously, it can be helpful to hide
|
|
172
|
+
all other data sets with the `i` key in order to just see the selected data
|
|
173
|
+
set.
|
|
174
|
+
|
|
175
|
+
### Ghost Cursor
|
|
176
|
+
|
|
177
|
+
If you want to make a comparison between two points, you can use the ghost
|
|
178
|
+
cursor. First, position the cursor at the start position. Then, press the `v`
|
|
179
|
+
key. Immediately, you should see in the bottom left corner, several metrics:
|
|
180
|
+
the difference in x positions (`dx`), the difference in y positions (`dy`), the
|
|
181
|
+
mean y value (`u`), and the standard deviation of y (`s`). Moving the cursor
|
|
182
|
+
will leave behind a ghost. As the cursor moves, the metrics will update to
|
|
183
|
+
reflect the range of values from the ghost cursor to the current cursor.
|
|
184
|
+
|
|
185
|
+
### Functions
|
|
186
|
+
|
|
187
|
+
Without writing any code, you can run a number of functions on the data and see
|
|
188
|
+
the results. First, press the `f` key. If you want the derivative or integral
|
|
189
|
+
of the data, press the `d` or `i` key, respectively. If you want to see the
|
|
190
|
+
Fourier transform, press the `f` key again. To smooth the data with a
|
|
191
|
+
triangular weighted moving average, enter the half width of the window and
|
|
192
|
+
press the `a` key. You can de-trend the data by entering the order of fitting
|
|
193
|
+
polynomial and then pressing the `d` key. Other functions are planned for the
|
|
194
|
+
future.
|
|
195
|
+
|
|
196
|
+
When one of the functions have been applied, the sides of the plotting box will
|
|
197
|
+
be rendered gray.
|
|
198
|
+
|
|
199
|
+
You can restore the original data by pressing the `F` key.
|
|
200
|
+
|
|
201
|
+
## Plots
|
|
202
|
+
|
|
203
|
+
```python
|
|
204
|
+
itrm.plot(x, y=None, label=None, rows=1, cols=1,
|
|
205
|
+
ea=0, lg=None, overlay=False):
|
|
206
|
+
```
|
|
207
|
+
|
|
208
|
+
The `plot` function is a non-interactive version of the `iplot` function. All
|
|
209
|
+
of the same parameters are provided, with the addition of the equal-axes (`ea`)
|
|
210
|
+
parameter.
|
|
211
|
+
|
|
212
|
+
| Single curve | Multiple curves |
|
|
213
|
+
| --------------- | --------------- |
|
|
214
|
+
|  |  |
|
|
215
|
+
|
|
216
|
+
## Bars
|
|
217
|
+
|
|
218
|
+
```python
|
|
219
|
+
itrm.bars(x, labels=None, cols=1, fat=False)
|
|
220
|
+
```
|
|
221
|
+
|
|
222
|
+
It can be convenient to plot a simple bar graph. The `x` input is the vector of
|
|
223
|
+
values. The `labels` input is a list of strings corresponding to the labels to
|
|
224
|
+
print before the bar of each value in `x`. If the `cols` input is greater than
|
|
225
|
+
1, it is the total width of characters including the labels. If it is less than
|
|
226
|
+
or equal to 1, it is the portion of the terminal window width which will be used
|
|
227
|
+
for the graph. If the `fat` input is set to `True`, the bars will be thick.
|
|
228
|
+
|
|
229
|
+
```
|
|
230
|
+
apples |========= |
|
|
231
|
+
oranges |========================================= |
|
|
232
|
+
bananas |==================================================|
|
|
233
|
+
pears |==================== |
|
|
234
|
+
grapes |============================ |
|
|
235
|
+
```
|
|
236
|
+
|
|
237
|
+
## Heat maps
|
|
238
|
+
|
|
239
|
+
```python
|
|
240
|
+
itrm.heat(matrix)
|
|
241
|
+
```
|
|
242
|
+
|
|
243
|
+
The `heat` function will generate a heat map of the `matrix` input using 24
|
|
244
|
+
shades of gray. Black is used for the lowest value and white for the highest
|
|
245
|
+
value. If `itrm.config.uni` is `True`, half-block characters from the Unicode
|
|
246
|
+
table will be used. If it is `False`, two spaces per element of the matrix will
|
|
247
|
+
be used.
|
|
248
|
+
|
|
249
|
+
| With Unicode | Without Unicode |
|
|
250
|
+
| ----------------- | ------------------- |
|
|
251
|
+
|  |  |
|
|
252
|
+
|
|
253
|
+
## Tables
|
|
254
|
+
|
|
255
|
+
```python
|
|
256
|
+
itrm.table(matrix, head=None, left=None, width=10, sep=' ')
|
|
257
|
+
```
|
|
258
|
+
|
|
259
|
+
You can print a nicely spaced table of the `matrix` data. The `head` and `left`
|
|
260
|
+
inputs are lists of header and left-most column labels, respectively, to print
|
|
261
|
+
around the `matrix`.
|
|
262
|
+
|
|
263
|
+
```
|
|
264
|
+
| Set 1 Set 2 Set 3
|
|
265
|
+
---------- | ---------- ---------- ----------
|
|
266
|
+
apples | 0.65802165 0.20015677 0.51074794
|
|
267
|
+
bananas | 0.42184098 0.46774988 0.39589918
|
|
268
|
+
pears | 0.79159879 0.89324181 0.57347394
|
|
269
|
+
oranges | 0.25932644 0.29973433 0.90646047
|
|
270
|
+
grapes | 0.2751687 0.40117769 0.58233234
|
|
271
|
+
```
|
|
272
|
+
|
|
273
|
+
## Sparsity
|
|
274
|
+
|
|
275
|
+
```python
|
|
276
|
+
itrm.spy(matrix)
|
|
277
|
+
```
|
|
278
|
+
|
|
279
|
+
If all you want to see is the sparsity of a matrix, use this function.
|
|
280
|
+
|
|
281
|
+
| With Unicode | Without Unicode |
|
|
282
|
+
| --------------------- | ----------------------- |
|
|
283
|
+
|  |  |
|
|
284
|
+
|
|
285
|
+
## Progress bars
|
|
286
|
+
|
|
287
|
+
```python
|
|
288
|
+
bar = itrm.Progress(K, cols=1)
|
|
289
|
+
bar.update(k)
|
|
290
|
+
```
|
|
291
|
+
|
|
292
|
+
There are many progress bar libraries available for Python. But, many of them
|
|
293
|
+
seem to be extremely over-complicated. TQDM, for example, includes over 20
|
|
294
|
+
source files. This library's implementation of a progress bar is a single,
|
|
295
|
+
one-page function. The `k` input is the counter of whatever for loop the
|
|
296
|
+
progress bar is reporting on. The `K` input is one greater than the largest
|
|
297
|
+
possible value of `k`, as in `for k in range(K):`. When the process is
|
|
298
|
+
completed, the total elapsed time will be displayed. If `cols` is not provided,
|
|
299
|
+
the full width of the current terminal window will be used.
|
|
300
|
+
|
|
301
|
+
```
|
|
302
|
+
44% ======================----------------------------- -00:00:02.1
|
|
303
|
+
```
|
|
304
|
+
|
|
305
|
+
[julia]: https://juliamono.netlify.app/
|
itrm-1.0.0/README.md
ADDED
|
@@ -0,0 +1,290 @@
|
|
|
1
|
+
# Interactive Terminal Utilities
|
|
2
|
+
|
|
3
|
+
```python
|
|
4
|
+
import itrm
|
|
5
|
+
```
|
|
6
|
+
|
|
7
|
+
This library offers several functions for visualizing data within the terminal.
|
|
8
|
+
This project does not exist just because it is cool. It exists because it fills
|
|
9
|
+
some needs which few other tools do. For many developers, engineers, and
|
|
10
|
+
scientists, the terminal is where much of their time is spent. Having to switch
|
|
11
|
+
contexts every time a plot is generated can be time consuming and annoying.
|
|
12
|
+
Furthermore, most plotting tools have fairly limited analysis capabilities. They
|
|
13
|
+
are great for generating final, beautiful figures, but not great at quickly
|
|
14
|
+
inspecting and understanding the data. Also, if you are working with a remote
|
|
15
|
+
server through SSH, visualizing the data with conventional tools can be very
|
|
16
|
+
tedious: save data to file, transfer data to local machine, write script just to
|
|
17
|
+
read and plot data, plot data, repeat. This library lets you directly visualize
|
|
18
|
+
and interact with the data, skipping all the tedium.
|
|
19
|
+
|
|
20
|
+
## Configuration
|
|
21
|
+
|
|
22
|
+
This library will generate a `config.ini` file in the same directory as the
|
|
23
|
+
library's installation. You can either manually modify the settings in that
|
|
24
|
+
file, or you can call the `itrm.config()` function. This function will take the
|
|
25
|
+
following parameters:
|
|
26
|
+
|
|
27
|
+
| Setting | Default | Description |
|
|
28
|
+
| --------- | :-----------: | --------------------------------- |
|
|
29
|
+
| `uni` | `True` | flag to use Unicode characters |
|
|
30
|
+
| `cols` | `60` | default column width |
|
|
31
|
+
| `rows` | `20` | default row height |
|
|
32
|
+
| `ar` | `0.48` | aspect ratio of characters |
|
|
33
|
+
| `cmap` | `spectrum` | color map |
|
|
34
|
+
|
|
35
|
+
### Unicode
|
|
36
|
+
|
|
37
|
+
Much of the plotting in the terminal performed by `itrm` relies on Unicode
|
|
38
|
+
characters. However, properly displaying those characters requires having a
|
|
39
|
+
monospace font with those specific glyphs defined. In fact, the default plotting
|
|
40
|
+
mode relies on braille characters, and relatively few fonts define those. If you
|
|
41
|
+
are looking for a good terminal font which supports all the Unicode used by this
|
|
42
|
+
library, try out [JuliaMono][julia]. However, you might not be interested in
|
|
43
|
+
downloading fonts, so this library can also forego all Unicode characters and
|
|
44
|
+
only rely on ASCII characters.
|
|
45
|
+
|
|
46
|
+
### Columns and Rows
|
|
47
|
+
|
|
48
|
+
Many terminals provide a means for a Python script to query the current size of
|
|
49
|
+
the terminal window in terms of the number of columns and rows of text. However,
|
|
50
|
+
not all terminals do. In those cases, it is good to have a fallback setting.
|
|
51
|
+
These are defined by the `cols` and `rows` configuration parameters.
|
|
52
|
+
|
|
53
|
+
### Aspect Ratio
|
|
54
|
+
|
|
55
|
+
Because all the plotting by this library uses text, the aspect ratio (ratio of
|
|
56
|
+
width to height) of the characters affects the apparent aspect ratio of curves.
|
|
57
|
+
So, a circle might look perfectly round or squashed depending on the font
|
|
58
|
+
chosen. This does not mean you need a new font, you just need to adjust the
|
|
59
|
+
aspect ratio setting, `ar`.
|
|
60
|
+
|
|
61
|
+
### Color Map
|
|
62
|
+
|
|
63
|
+
By default, the color map used is `spectrum`, a rainbow of colors. Using the
|
|
64
|
+
`cmap` parameter, you can pick any of the following color maps: `spectrum`,
|
|
65
|
+
`viridis`, `grays`, `reds`, `greens`, `blues`, or `4bit`. All but the last color
|
|
66
|
+
map use platform-independent, 8-bit colors. The last color map, `4bit`, lets use
|
|
67
|
+
control the colors with your terminal settings, instead.
|
|
68
|
+
|
|
69
|
+
## Interactive Plots
|
|
70
|
+
|
|
71
|
+
```python
|
|
72
|
+
itrm.iplot(x, y=None, label=None, rows=1, cols=1,
|
|
73
|
+
lg=None, overlay=False):
|
|
74
|
+
```
|
|
75
|
+
|
|
76
|
+
### Parameters
|
|
77
|
+
|
|
78
|
+
The `iplot` function will render all the data points defined by `x` and `y` to
|
|
79
|
+
the terminal. The inputs `x` and `y` can be vectors, matrices, or lists of such
|
|
80
|
+
arrays. Each **row** of a matrix is treated as a separate curve. Note, this is
|
|
81
|
+
different from MatPlotLib, in which each *column* is treated as a separate row.
|
|
82
|
+
(This difference is intentional, as in the author's opinion varying time along
|
|
83
|
+
columns means each column in a matrix can be treated as a vector. This
|
|
84
|
+
arrangement works very well with in linear algebra, especially matrix
|
|
85
|
+
multiplication with a "set" of vectors over time.)
|
|
86
|
+
|
|
87
|
+
The shapes of `x` and `y` do not have to be the same, but they must be
|
|
88
|
+
compatible. So, `x` could be a vector and `y` could be a matrix as long as the
|
|
89
|
+
length of `x` equals the number of columns of `y`.
|
|
90
|
+
|
|
91
|
+
If only `x` is given, it will be interpreted as the `y` values, and the `x`
|
|
92
|
+
values will be the array of indices.
|
|
93
|
+
|
|
94
|
+
When the plot is printed, the graph is rendered within a box and the ranges of
|
|
95
|
+
`x` and `y` are listed in the bottom left corner. So,
|
|
96
|
+
|
|
97
|
+
```
|
|
98
|
+
(0:99, -1.5:1.5)
|
|
99
|
+
```
|
|
100
|
+
|
|
101
|
+
means that `x` ranges from `0` to `99` and `y` ranges from `-1.5` to `1.5`.
|
|
102
|
+
|
|
103
|
+
If a `label` is given, this will be printed in the bottom right of the plot box.
|
|
104
|
+
It can also be a list of strings. If the length of the list is the same as the
|
|
105
|
+
number of data sets (each row of a matrix is a different data set), then each
|
|
106
|
+
string in the list will be displayed with the respective data set. If the length
|
|
107
|
+
of the list is one greater, the first string will be displayed for the whole
|
|
108
|
+
plot.
|
|
109
|
+
|
|
110
|
+
The `rows` and `cols` parameters let you specify the number of terminal text
|
|
111
|
+
rows and columns to use for the plot, respectively. For each of these, if the
|
|
112
|
+
value is less than or equal to 1, it represents a portion of the available space
|
|
113
|
+
to use. For example, if `rows` is `0.5`, then half the number of rows of the
|
|
114
|
+
current terminal window will be used for the plot. If the value is greater than
|
|
115
|
+
1, it represents the absolute number of rows or columns to use. Also, if the
|
|
116
|
+
size of the current terminal cannot be obtained, the available space will
|
|
117
|
+
default to `20` rows and `60` columns.
|
|
118
|
+
|
|
119
|
+
You can set the x or y axes to logarithmic scaling by setting the `lg` parameter
|
|
120
|
+
to one of `"x"`, `"y"`, or `"xy"`. Note that the values reported for the view
|
|
121
|
+
and the cursor will be in the original scaling, not logarithmic.
|
|
122
|
+
|
|
123
|
+
To prevent your terminal history from extending each time a new plot is
|
|
124
|
+
rendered, you can print a new plot over a previous plot by setting the `overlay`
|
|
125
|
+
parameter to `True`. This can be especially useful when there are multiple plots
|
|
126
|
+
to render (like for an animation) but you do not want your terminal history to
|
|
127
|
+
fill up quickly.
|
|
128
|
+
|
|
129
|
+
### Keybindings
|
|
130
|
+
|
|
131
|
+
The `iplot` function provides interactivity through a vertical cursor. You can
|
|
132
|
+
move the cursor left and right, at normal speed or fast speed. You can zoom in
|
|
133
|
+
and out. And, you can cycle through which rows of the `x` and `y` data to focus
|
|
134
|
+
on. Note, `iplot` is designed for monotonically-increasing `x` values, and,
|
|
135
|
+
consequently, does not support equal axis scaling.
|
|
136
|
+
|
|
137
|
+

|
|
138
|
+
|
|
139
|
+
The following table details the shortcut keys:
|
|
140
|
+
|
|
141
|
+
| Keys | Function | | Keys | Function |
|
|
142
|
+
| :------------: | ---------------------- | - | :------------: | ------------------------ |
|
|
143
|
+
| `q`, `⌫`, `↵` | exit interactive plot | | `j`, `s`, `↓` | zoom in |
|
|
144
|
+
| `h`, `a`, `←` | move cursor left | | `k`, `w`, `↑` | zoom out |
|
|
145
|
+
| `l`, `d`, `→` | move cursor right | | `J`, `S`, `⇧↓` | zoom in fast |
|
|
146
|
+
| `H`, `A`, `⇧←` | move cursor left fast | | `K`, `W`, `⇧↑` | zoom out fast |
|
|
147
|
+
| `L`, `D`, `⇧→` | move cursor right fast | | `n` | select next data set |
|
|
148
|
+
| `g` | move cursor to start | | `N` | select previous data set |
|
|
149
|
+
| `G` | move cursor to end | | `i` | toggle individual view |
|
|
150
|
+
| `c`, `z` | center view on cursor | | `v` | toggle ghost cursor |
|
|
151
|
+
| `x` | toggle x log scaling | | `f` | start function |
|
|
152
|
+
| `y` | toggle y log scaling | | `F` | restore original data |
|
|
153
|
+
|
|
154
|
+
### Individual Data Sets
|
|
155
|
+
|
|
156
|
+
When many data sets are being plotted simultaneously, it can be helpful to hide
|
|
157
|
+
all other data sets with the `i` key in order to just see the selected data
|
|
158
|
+
set.
|
|
159
|
+
|
|
160
|
+
### Ghost Cursor
|
|
161
|
+
|
|
162
|
+
If you want to make a comparison between two points, you can use the ghost
|
|
163
|
+
cursor. First, position the cursor at the start position. Then, press the `v`
|
|
164
|
+
key. Immediately, you should see in the bottom left corner, several metrics:
|
|
165
|
+
the difference in x positions (`dx`), the difference in y positions (`dy`), the
|
|
166
|
+
mean y value (`u`), and the standard deviation of y (`s`). Moving the cursor
|
|
167
|
+
will leave behind a ghost. As the cursor moves, the metrics will update to
|
|
168
|
+
reflect the range of values from the ghost cursor to the current cursor.
|
|
169
|
+
|
|
170
|
+
### Functions
|
|
171
|
+
|
|
172
|
+
Without writing any code, you can run a number of functions on the data and see
|
|
173
|
+
the results. First, press the `f` key. If you want the derivative or integral
|
|
174
|
+
of the data, press the `d` or `i` key, respectively. If you want to see the
|
|
175
|
+
Fourier transform, press the `f` key again. To smooth the data with a
|
|
176
|
+
triangular weighted moving average, enter the half width of the window and
|
|
177
|
+
press the `a` key. You can de-trend the data by entering the order of fitting
|
|
178
|
+
polynomial and then pressing the `d` key. Other functions are planned for the
|
|
179
|
+
future.
|
|
180
|
+
|
|
181
|
+
When one of the functions have been applied, the sides of the plotting box will
|
|
182
|
+
be rendered gray.
|
|
183
|
+
|
|
184
|
+
You can restore the original data by pressing the `F` key.
|
|
185
|
+
|
|
186
|
+
## Plots
|
|
187
|
+
|
|
188
|
+
```python
|
|
189
|
+
itrm.plot(x, y=None, label=None, rows=1, cols=1,
|
|
190
|
+
ea=0, lg=None, overlay=False):
|
|
191
|
+
```
|
|
192
|
+
|
|
193
|
+
The `plot` function is a non-interactive version of the `iplot` function. All
|
|
194
|
+
of the same parameters are provided, with the addition of the equal-axes (`ea`)
|
|
195
|
+
parameter.
|
|
196
|
+
|
|
197
|
+
| Single curve | Multiple curves |
|
|
198
|
+
| --------------- | --------------- |
|
|
199
|
+
|  |  |
|
|
200
|
+
|
|
201
|
+
## Bars
|
|
202
|
+
|
|
203
|
+
```python
|
|
204
|
+
itrm.bars(x, labels=None, cols=1, fat=False)
|
|
205
|
+
```
|
|
206
|
+
|
|
207
|
+
It can be convenient to plot a simple bar graph. The `x` input is the vector of
|
|
208
|
+
values. The `labels` input is a list of strings corresponding to the labels to
|
|
209
|
+
print before the bar of each value in `x`. If the `cols` input is greater than
|
|
210
|
+
1, it is the total width of characters including the labels. If it is less than
|
|
211
|
+
or equal to 1, it is the portion of the terminal window width which will be used
|
|
212
|
+
for the graph. If the `fat` input is set to `True`, the bars will be thick.
|
|
213
|
+
|
|
214
|
+
```
|
|
215
|
+
apples |========= |
|
|
216
|
+
oranges |========================================= |
|
|
217
|
+
bananas |==================================================|
|
|
218
|
+
pears |==================== |
|
|
219
|
+
grapes |============================ |
|
|
220
|
+
```
|
|
221
|
+
|
|
222
|
+
## Heat maps
|
|
223
|
+
|
|
224
|
+
```python
|
|
225
|
+
itrm.heat(matrix)
|
|
226
|
+
```
|
|
227
|
+
|
|
228
|
+
The `heat` function will generate a heat map of the `matrix` input using 24
|
|
229
|
+
shades of gray. Black is used for the lowest value and white for the highest
|
|
230
|
+
value. If `itrm.config.uni` is `True`, half-block characters from the Unicode
|
|
231
|
+
table will be used. If it is `False`, two spaces per element of the matrix will
|
|
232
|
+
be used.
|
|
233
|
+
|
|
234
|
+
| With Unicode | Without Unicode |
|
|
235
|
+
| ----------------- | ------------------- |
|
|
236
|
+
|  |  |
|
|
237
|
+
|
|
238
|
+
## Tables
|
|
239
|
+
|
|
240
|
+
```python
|
|
241
|
+
itrm.table(matrix, head=None, left=None, width=10, sep=' ')
|
|
242
|
+
```
|
|
243
|
+
|
|
244
|
+
You can print a nicely spaced table of the `matrix` data. The `head` and `left`
|
|
245
|
+
inputs are lists of header and left-most column labels, respectively, to print
|
|
246
|
+
around the `matrix`.
|
|
247
|
+
|
|
248
|
+
```
|
|
249
|
+
| Set 1 Set 2 Set 3
|
|
250
|
+
---------- | ---------- ---------- ----------
|
|
251
|
+
apples | 0.65802165 0.20015677 0.51074794
|
|
252
|
+
bananas | 0.42184098 0.46774988 0.39589918
|
|
253
|
+
pears | 0.79159879 0.89324181 0.57347394
|
|
254
|
+
oranges | 0.25932644 0.29973433 0.90646047
|
|
255
|
+
grapes | 0.2751687 0.40117769 0.58233234
|
|
256
|
+
```
|
|
257
|
+
|
|
258
|
+
## Sparsity
|
|
259
|
+
|
|
260
|
+
```python
|
|
261
|
+
itrm.spy(matrix)
|
|
262
|
+
```
|
|
263
|
+
|
|
264
|
+
If all you want to see is the sparsity of a matrix, use this function.
|
|
265
|
+
|
|
266
|
+
| With Unicode | Without Unicode |
|
|
267
|
+
| --------------------- | ----------------------- |
|
|
268
|
+
|  |  |
|
|
269
|
+
|
|
270
|
+
## Progress bars
|
|
271
|
+
|
|
272
|
+
```python
|
|
273
|
+
bar = itrm.Progress(K, cols=1)
|
|
274
|
+
bar.update(k)
|
|
275
|
+
```
|
|
276
|
+
|
|
277
|
+
There are many progress bar libraries available for Python. But, many of them
|
|
278
|
+
seem to be extremely over-complicated. TQDM, for example, includes over 20
|
|
279
|
+
source files. This library's implementation of a progress bar is a single,
|
|
280
|
+
one-page function. The `k` input is the counter of whatever for loop the
|
|
281
|
+
progress bar is reporting on. The `K` input is one greater than the largest
|
|
282
|
+
possible value of `k`, as in `for k in range(K):`. When the process is
|
|
283
|
+
completed, the total elapsed time will be displayed. If `cols` is not provided,
|
|
284
|
+
the full width of the current terminal window will be used.
|
|
285
|
+
|
|
286
|
+
```
|
|
287
|
+
44% ======================----------------------------- -00:00:02.1
|
|
288
|
+
```
|
|
289
|
+
|
|
290
|
+
[julia]: https://juliamono.netlify.app/
|