mcastorina / graph-cli

Flexible command line tool to create graphs from CSV data
783 stars 29 forks source link

annotation / text does not work on timeseries graphs #21

Open mcastorina opened 5 years ago

mcastorina commented 5 years ago

this may require pushing the auto-fill code from options.py into graph.py where we decide if the xcol is timeseries or not

mcastorina commented 5 years ago

https://stackoverflow.com/questions/11067368/annotate-time-series-plot-in-matplotlib#11068038

xxxserxxx commented 2 years ago

Is there anything a user can do about this? It's not just time series. From the --bar example:

$ graph samples/bar.csv

bar

with the X-axis automagically converted to indexes. However, per the original ticket:

$ graph samples/bar.csv --annotate '1=Oranges'
Traceback (most recent call last):
  File "/usr/bin/graph", line 33, in <module>
    sys.exit(load_entry_point('graph-cli==0.1.19', 'console_scripts', 'graph')())
  File "/usr/lib/python3.10/site-packages/graph_cli/main.py", line 17, in main
    create_graph(graphs)
  File "/usr/lib/python3.10/site-packages/graph_cli/graph.py", line 323, in create_graph
    apply_globals(plt, ax, graphs)
  File "/usr/lib/python3.10/site-packages/graph_cli/graph.py", line 378, in apply_globals
    slope = get_slope(df, xcol, ycol, xpos=pos[0])
  File "/usr/lib/python3.10/site-packages/graph_cli/graph.py", line 421, in get_slope
    df['dx'] = df[xcol].diff()
  File "/usr/lib/python3.10/site-packages/pandas/core/series.py", line 2697, in diff
    result = algorithms.diff(self._values, periods)
  File "/usr/lib/python3.10/site-packages/pandas/core/algorithms.py", line 1651, in diff
    out_arr[res_indexer] = op(arr[res_indexer], arr[lag_indexer])
TypeError: unsupported operand type(s) for -: 'str' and 'str'

It's not per se a bug, but it'd be awfully useful to be able to annotate in cases when the X axis is being indexed -- for example, in this case, where the viewer would otherwise not be able to tell which index was Oranges by looking at the graph.

Is there a work-around? Or is the only solution to mangle the input data and replace the X column with a sequence?