Beefy Boxes and Bandwidth Generously Provided by pair Networks
laziness, impatience, and hubris
 
PerlMonks  

Plaintext plot - existing sofware?

by parv (Parson)
on Jul 21, 2021 at 08:10 UTC ( [id://11135247]=perlquestion: print w/replies, xml ) Need Help??

parv has asked for the wisdom of the Perl Monks concerning the following question:

Before I write a program to chart x-y values in plain text (again), does anyone know of any software|code to share which would spit out "scatter plot" on standard output (or in a file) in plain text (no image-graphs, Excel, LibreOffice, etc)?

I could not find something relevant here ("text plot"); on MetaCPAN; via DuckDuckGo.

Replies are listed 'Best First'.
Re: Plaintext plot - existing sofware?
by bliako (Monsignor) on Jul 21, 2021 at 12:12 UTC

    Programming on the shoulders of Giants:

    use strict; use warnings; use Chart::Gnuplot; my @x = (1..5); my @y = map { rand() } @x; my $dataSet = Chart::Gnuplot::DataSet->new( xdata => \@x, ydata => \@y, title => "Plotting a line from Perl arrays", style => "linespoints", ); # Create chart object and specify the properties of the chart my $chart = Chart::Gnuplot->new( title => "Simple testing", xlabel => "My x-axis label", ylabel => "My y-axis label", terminal => 'dumb', ); # Plot the data set on the chart $chart->plot2d($dataSet);
    + Simple testing + + 0.8 +------------------------------------------------------------ +-----+ | + + + *A* + + + + | 0.7 |-+ Plot***g a**ine from Perl arrays *** +A***-| | **** * + *| 0.6 |-+ *** * + **-| | *** * + * | 0.5 |-+ A* * +* +-| | ** ** * + | 0.4 |-+ ** * ** + +-| | ** * * + | | ** * * + | 0.3 |-+ ** * * + +-| | ** ** * + | 0.2 |-+** * ** + +-| |** * + | 0.1 |-+ A + +-| | + + + + + + + + | 0 +------------------------------------------------------------ +-----+ 1 1.5 2 2.5 3 3.5 4 4.5 + 5 My x-axis label

    bw, bliako

      Thanks for showing that gnuplot can produce a text plot. I got overwhelmed by the documentation about multitude of terminals; did not find that myself earlier.

        my phd was a loooong gnuplot script

        and here is the time-honored japhy - my first one!

        use GD::Simple; use Chart::Gnuplot; my $image = GD::Simple->new(400, 40); $image->trueColor(1); $image->bgcolor('white'); $image->fgcolor('black'); $image->font('courier'); $image->fontsize(20); $image->moveTo(1,21); #$image->string("Just Another Perl Hacker"); $image->string("just another perl hacker"); my $W = $image->width(); my $H = $image->height(); my ($x, $y, $r, @onX, @onY); for ($x=0; $x<$image->width(); $x++) { for ($y=0; $y<$image->height(); + $y++) { $r = $image->getPixel($x,$y); if( $r > 0 ){ push @onY, $x; push @onX, $y; } }} my $dataSet = Chart::Gnuplot::DataSet->new( xdata => \@onX, ydata => \@onY, title => undef, style => "dots", ); # Create chart object and specify the properties of the chart my $chart = Chart::Gnuplot->new( title => undef, xlabel => undef, ylabel => undef, terminal => 'dumb size 40,180', ); # Plot the data set on the chart $chart->plot2d($dataSet);
        400 +-----------------------------+ | + + + | | | | | | | | | | | | . . | | .. . . | | .. . . | | .. . . . | | .. .. .. .. .. . | | .. . . | | . . . | | | | . .. .. .. . | | .. . .. . . | | .. .. . . | | .. .. . . | | .. .. .. .. .. | | .. .. .. . | | | 350 |-+ .. . . +-| | .. . . .. . | | .. .. . .. .. . | | .. .. . | | .. .. .. .. .. .. .. . | | . . . | | | | .. .. . .. | | .. . .. . | | .. . . | | .. . . | | .. .. .. .. .. . | | . .. .. | | | | . . | | .. .. .. .. .. . | | .. .. .. . | | .. .. . . | | .. .. .. .. . | | . .. .. | | | | . . | 300 |-+ .. .. .. .. .. . +-| | .. . | | .. . . | | .. .. .. .. .. .. .. . | | .. .. .. .. .. .. .. . | | | | | | | | | | | | | | | | | | . . | | . . | | .. .. .. .. .. .. .. . | | .. .. .. .. .. .. .. . | | . . . | | . . . | | | | .. . | | .. . . | 250 |-+ .. . . . +-| | .. .. .. .. .. . | | .. .. .. .. .. . | | .. . . | | | | . .. .. | | . .. .. .. . | | .. . .. . . | | .. .. . . | | .. . .. .. . | | . .. .. .. .. | | .. . | | .. .. .. . | | .. .. . .. . | | .. . . | | .. . . .| | .. .. . .. .. . .| | .. .. .. .. .. .. .. .| | .. .| | | | | | | 200 |-+ +-| | | | | | | | .. . | | .. . . | | .. . . . | | .. .. .. .. .. . | | .. .. .. .. .. . | | .. . . | | | | . .. .. | | . .. .. .. . | | .. . .. . . | | .. .. . . | | .. . .. .. . | | . .. .. .. .. | | .. . | | . . | | .. .. .. .. .. . | | .. . . . | | .. | 150 |-.. .. .. .. .. .. .. . +-| | .. .. .. .. .. .. .. . | | . . . | | | | .. .. . | | .. . . | | .. . . | | .. .. .. .. .. .. .. . | | .. .. .. .. .. .. . | | .. | | . | | . .. .. .. .. | | .. . .. . | | .. . . | | .. . .. . | | . .. .. .. .. | | . | | . . | | .. .. .. .. .. . | | .. . . . | | .. | | .. . . . | 100 |-+ .. .. .. .. .. . +-| | .. . . | | . . | | .. .. .. .. . | | .. .. .. .. .. . | | .. .. . . | | .. .. . . | | .. .. .. .. . | | . . | | | | | | | | | | | | | | | | | | .. . | | .. . . | | .. . . | | . .. .. .. .. .. .. . | | .. .. .. .. .. .. .. | 50 |-+ .. +-| | | | .. .. . .. .. | | .. .. .. .. .. . | | .. .. . . | | .. . .. . . | | .. .. . . .. . | | . .. . | | . . | | .. .. .. .. .. . | | .. .. .. .. .. . | | .. . .. | | . . | | .. .. .. .. .. . | | .. | | | | .. .. .. .. .. .. . | | .. .. .. .. .. .. .. .. .| | .. .. .| | .. .| | .. .| | + + + | 0 +-----------------------------+ 5 10 15 20 25

        bw, bliako

Re: Plaintext plot - existing sofware?
by erix (Prior) on Jul 21, 2021 at 08:36 UTC

    "ascii plot" on cpan seems to find useful modules (haven't tried any of them recently).

    (off-topic, just for the hack of it, here is a ascii-graph written in SQL: Mandelbrot Set)

      That SQL "query" result was glorious! :-]

      I thought I had tried ScatterPlot already; does not look like so now; will try soon and report.

      App::AsciiChart looked promising (missed earlier) but it generates its own Y values.

        ScatterPlot worked in the way I wanted to ...

        elapsed:day
        5.3                                         ... 
        |                                        ....   
        |                                    .....      
        |                                 ....          
        |                             .....             
        |                       .......                 
        |                 .......                size:T 
        0.0        ........                        20.7 
        0.0.........------------------------------------
        
        (This & following 2 lines I have added myself.)
        X: amount of data transferred, TB;
        Y: number of days elapsed.
        

        Above is not very linear graph of data transferred via zfs send | ssh other-host zfs recv from one FreeBSD 12 host to another. After 5.3 days, 20.7 TB of data (total is 47.9 TB) had been transferred.

        As of now, linear regression suggests ~10 more days to finish. Polynomial curve fit (of degree 3) — which had matched the plot more than linear regression — estimates ~30 days. Yikes!

Re: Plaintext plot - existing sofware?
by Fletch (Bishop) on Jul 21, 2021 at 13:17 UTC

    If you don't mind an external dependency and can generate suitable JSON you could pipe to jp and let it do the heavy lifting.

    The cake is a lie.
    The cake is a lie.
    The cake is a lie.

      Thanks for the suggestion of Go "jp".

      At the time I was looking for rather self-contained software. After not finding anything working then, I broke down to import data in Libreoffice which has been already present.

Re: Plaintext plot - existing sofware?
by hippo (Bishop) on Jul 21, 2021 at 09:08 UTC
    Before I write a program to chart x-y values in plain text (again)

    If you have written it already, why would you write it again? Just use the code you already have. DRY.


    🦛

      For my part the answer is: Because I’m going to do it right¹ this time.
       

          ¹ Where “right,” despite all intentions, only ends up meaning differently.

      Because I do not have the source anymore from last work.

A reply falls below the community's threshold of quality. You may see it by logging in.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://11135247]
Approved by GrandFather
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others imbibing at the Monastery: (5)
As of 2024-03-28 14:22 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found