red-data-tools / YouPlot

A command line tool that draw plots on the terminal.
MIT License
4.17k stars 57 forks source link

Log scales ? #43

Open katotheo opened 1 year ago

katotheo commented 1 year ago

Is log scales possible? Any plans to add it? Thanks.

kojix2 commented 1 year ago

Hello. I see that you are proposing to add a log scale. Could you tell me what commands and command line options you are imagining?

katotheo commented 1 year ago

Something per axis, e.g. --ysetlogscale defaulting to log of 10, or pass a number for different log...

I suppose one could process the data before feeding them to the plotter, but it would be a good convenience if plotter took care of that...

kojix2 commented 1 year ago

You can use log scale for bar and count.

curl -sL https://git.io/ISLANDScsv \
| sort -nk2 -t, \
| tail -n15 \
| uplot bar -d, -t "Areas of the World's Major Landmasses" --xscale log
                   Areas of the World's Major Landmasses
                 ┌                                        ┐ 
         Britain ┤■■■■■■■■■■■■■■ 84.0                       
          Honshu ┤■■■■■■■■■■■■■■ 89.0                       
         Sumatra ┤■■■■■■■■■■■■■■■■■ 183.0                   
          Baffin ┤■■■■■■■■■■■■■■■■■ 184.0                   
      Madagascar ┤■■■■■■■■■■■■■■■■■ 227.0                   
          Borneo ┤■■■■■■■■■■■■■■■■■■ 280.0                  
      New Guinea ┤■■■■■■■■■■■■■■■■■■ 306.0                  
       Greenland ┤■■■■■■■■■■■■■■■■■■■■■ 840.0               
       Australia ┤■■■■■■■■■■■■■■■■■■■■■■■■■ 2968.0          
          Europe ┤■■■■■■■■■■■■■■■■■■■■■■■■■■ 3745.0         
      Antarctica ┤■■■■■■■■■■■■■■■■■■■■■■■■■■■ 5500.0        
   South America ┤■■■■■■■■■■■■■■■■■■■■■■■■■■■■ 6795.0       
   North America ┤■■■■■■■■■■■■■■■■■■■■■■■■■■■■■ 9390.0      
          Africa ┤■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■ 11506.0    
            Asia ┤■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■ 16988.0   

https://github.com/red-data-tools/YouPlot/blob/a2d04dafa3e8613367b40dbeb6fffde7db61c1b0/lib/youplot/parser.rb#L312-L322

On the other hand, line, scatter, density, etc. cannot use log scale.

YouPlot is mostly a wrapper for the backend library UnicodePlot. So, it depends on unicode_plot whether log scaling is currently supported.

kojix2 commented 1 year ago

Reading the README.md of the original Julia implementation of UnicodePlot, it appears that log scale is now supported.

image

And I hope Ruby's UnicodePlot will support it as well.

katotheo commented 1 year ago

Sounds great, I'll use bar or count.

Shall we close this or keep it open as a reminder for the work for line, scatter, etc. ?

kojix2 commented 1 year ago

Please leave this issue Open.

llimllib commented 1 year ago

It would be very useful for hist as well, ex the graph this presents is not super useful:

$ cat /usr/share/dict/words | grep -o ...$ | sort | uniq -c | uplot hist -n 20
                      ┌                                        ┐ 
   [    0.0,   500.0) ┤▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇ 4068   
   [  500.0,  1000.0) ┤ 45                                       
   [ 1000.0,  1500.0) ┤ 16                                       
   [ 1500.0,  2000.0) ┤ 4                                        
   [ 2000.0,  2500.0) ┤ 5                                        
   [ 2500.0,  3000.0) ┤ 5                                        
   [ 3000.0,  3500.0) ┤ 4                                        
   [ 3500.0,  4000.0) ┤ 1                                        
   [ 4000.0,  4500.0) ┤ 1                                        
   [ 4500.0,  5000.0) ┤ 1                                        
   [ 5000.0,  5500.0) ┤ 0                                        
   [ 5500.0,  6000.0) ┤ 1                                        
   [ 6000.0,  6500.0) ┤ 1                                        
   [ 6500.0,  7000.0) ┤ 1                                        
   [ 7000.0,  7500.0) ┤ 0                                        
   [ 7500.0,  8000.0) ┤ 0                                        
   [ 8000.0,  8500.0) ┤ 0                                        
   [ 8500.0,  9000.0) ┤ 0                                        
   [ 9000.0,  9500.0) ┤ 1                                        
                      └                                        ┘ 

(interpretation: most words don't end in a common ending, but a few endings are very very common)