Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Conversation

@lovromazgon
Copy link
Contributor

This PR adds support to csvtk plot line to plot graphs where X is a nominal value. This can be done by using the flag --data-field-x-nominal.

All unique X values are collected, sorted and assigned an index. The corresponding value is also shown in the graph marker instead of the index. This opens up the ability to plot graphs for datasets, where X is a date, as long as it's formatted in a way that is sortable (e.g. YYYY-MM-DD HH:MM:SS). Related to this issue #179.

Example:

File example.csv:

time,value
2025-03-13 12:00,23.45
2025-03-13 12:01,67.89
2025-03-13 12:02,45.67
2025-03-13 12:03,89.12
2025-03-13 12:04,12.34
2025-03-13 12:05,78.90
2025-03-13 12:06,56.78
2025-03-13 12:07,34.56
2025-03-13 12:08,90.12
2025-03-13 12:09,10.01

Running command:

csvtk plot line example.csv -x time -y value --data-field-x-nominal -o example.jpg

Produces:
example

@shenwei356 shenwei356 merged commit 33a1fa0 into shenwei356:master Mar 14, 2025
shenwei356 added a commit that referenced this pull request Mar 14, 2025
@shenwei356
Copy link
Owner

Geat! Thank you so much @lovromazgon

I've updated the docs, and added an example:

$ csvtk pretty testdata/date2value.csv
date    views   unique_visitors
-----   -----   ---------------
03/01   7       5              
03/02   5       3              
03/03   39      21             
03/04   37      20             
03/05   59      25             
03/06   23      14             
03/07   49      24

$ cat testdata/date2value.csv \
    | csvtk gather -f 2- -k type -v count \
    | csvtk plot line --group-field type -x date -y count --data-field-x-nominal \
    > testdata/figures/line_plot_date.png 

line_plot_date

@lovromazgon
Copy link
Contributor Author

Thanks! This will be useful for our benchmarking efforts on Conduit!

@lovromazgon
Copy link
Contributor Author

Hey @shenwei356, can you tell me approximately when you intend to cut the 0.34 release? 🙏 Thanks!

@shenwei356
Copy link
Owner

are you in hurry?
ah, I forgot to send you the binaries, will send tomorrow.

you can also compile from the source: https://bioinf.shenwei.me/csvtk/download/#method-6-compiling-from-source-latest-stabledev-version

@lovromazgon
Copy link
Contributor Author

Oh no, no need to send me the binaries, locally I can compile it myself of course. I'm asking, because I'd like to include the tool in a CI flow and it would be neat if I wouldn't have to depend on a commit, but rather on a released version. That's a minor issue though, I can live with it, if you wanted to postpone the release and include more features 😉

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants