Skip to content

Commit

Permalink
Comments and general cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
mcastorina committed Nov 11, 2018
1 parent 8caff6c commit 380905b
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 6 deletions.
8 changes: 8 additions & 0 deletions EXAMPLES.md
Expand Up @@ -2,48 +2,56 @@
An extended list of examples to demonstrate features and usage.

```
# example 1
graph samples/sine.csv --marker '' --fill
```

![example-01](screenshots/example-01.png)

```
# example 2
graph samples/sine.csv --marker '' --xrange 0:500
```

![example-02](screenshots/example-02.png)

```
# example 3
graph samples/sine-cosine.csv --marker '' --style='-.,-' --ylabel 'y' --legend 'sin,cos'
```

![example-03](screenshots/example-03.png)

```
# example 4
graph samples/bar.csv --bar
```

![example-04](screenshots/example-04.png)

```
# example 5
graph samples/bar.csv --bar --width 0.4 --offset='-0.2,0.2' --ylabel 'Price ($)'
```

![example-05](screenshots/example-05.png)

```
# example 6
graph samples/avocado.csv -y 2 --resample 2W
```

![example-06](screenshots/example-06.png)

```
# example 7
graph samples/sine.csv -t '0:-0.08=start' -t '250=high' -t '500=mid' -t '750=low' -t '1000=end' --marker '' --xscale 250 --yscale 0.5
```

![example-07](screenshots/example-07.png)

```
# example 8
graph samples/sine-cosine.csv --marker '' --annotate '500=sin' --annotate '750=cos' --annotate '180:-0.8:90:-0.95=legend'
```

Expand Down
6 changes: 4 additions & 2 deletions OPTIONS.md
Expand Up @@ -9,6 +9,8 @@ These notes explain some features that might not be obvious.
- All line specific options can be a comma separated list of values
- Due to argparse quirks, options that need to start with `-` must be written using `--opt=val`
- Example: `--style='-.'`
- The annotate flag will cycle through available lines if only xpos is specified
- Example 8 in [EXAMPLES.md](EXAMPLES.md) shows this

### Required Options

Expand Down Expand Up @@ -41,8 +43,8 @@ These options persist across chains and are generally set only once.
| --ytick-align | | center | ytick label text alignment |
| --ylabel-fontsize | | 10 | ylabel font size |
| --grid | | -. | grid linestyle |
| --text | -t | | add text to the graph (xpos=text | xpos:ypos=text) |
| --annotate | -a | | add annotation (text and arrow) to the graph (xpos=text | xpos:ycol=text | xtext:ytext:xpos:ypos=text) |
| --text | -t | | add text to the graph (xpos=text \| xpos:ypos=text) |
| --annotate | -a | | add annotation (text and arrow) to the graph (xpos=text \| xpos:ycol=text \| xtext:ytext:xpos:ypos=text) |
| --chain | -C | false | use this option to combine graphs into a single image |

### Line Specific Options
Expand Down
2 changes: 1 addition & 1 deletion README.md
Expand Up @@ -45,7 +45,7 @@ graph samples/sine.csv --resample 125 -o sine-resample.png
![sine-resample](screenshots/sine-resample.png)

```
graph samples/avocado.csv --resample 1W -o avocado-resample.png
graph samples/avocado.csv -x 'Date' -y 'AveragePrice' --resample 1W -o avocado-resample.png
```

![avocado-resample](screenshots/avocado-resample.png)
Expand Down
3 changes: 3 additions & 0 deletions graph_cli/graph_cli/graph.py
Expand Up @@ -140,6 +140,9 @@ def get_graph_def(xcol, ycol, legend, color, style, fill, marker, width,
xcol, ycol = df[xcol.name], df[ycol.name]
del df
del timeseries
# need to delete all local variables so locals() works
# TODO: move preprocessing into separate function to avoid this
# balancing act

kvs = locals()
g = Graph()
Expand Down
7 changes: 4 additions & 3 deletions graph_cli/graph_cli/options.py
Expand Up @@ -24,11 +24,11 @@ def get_column_name(df, col):
def get_ypos(df, xpos, xycols):
pos = []
for xcol, ycol in xycols:
df = df.copy()
df2 = df.copy()
# minimize distance to xpos
df[xcol] = (df[xcol] - xpos).pow(2)
df2[xcol] = (df2[xcol] - xpos).pow(2)
# get mean of all y positions
pos += [df.iloc[df[xcol].idxmin()][ycol]]
pos += [df2.iloc[df2[xcol].idxmin()][ycol]]
return 1.0 * sum(pos) / len(pos)

def get_ofs(df, xcols, ycols, pos=(0, 0), mag=0.1, rad=pi/3, figsize=(16, 10)):
Expand Down Expand Up @@ -239,6 +239,7 @@ def fill_global_args(args, df):
pos[0] = float(pos[0])
if len(pos) == 1:
# xpos
# add ypos as the mean of all lines at that xpos
pos += [get_ypos(df, pos[0], zip(args.xcol, args.ycol))]
args.text[i] = (*pos, msg)
args.text = (args.text, True)
Expand Down

0 comments on commit 380905b

Please sign in to comment.