Coder Social home page Coder Social logo

colchart's Introduction

colchart

Drawing a pseudo 3D bar graph in gnuplot requires preprocessing the data. This program is the answer to the homework problem posed by the above link.

中文: 從試算表產生柱柱圖(三次元長條圖)

1. For the Impatient

Usage:

    ./mat2list.pl -r '1987:' -c '1:' temperature.csv > rugged.txt
    ./pt2sq.pl rugged.txt > colchart.txt

Then inside gnuplot:

    load "colchart.gpt"

to draw the column chart (3d bar chart) and generate two png files "rugged.png" and "colchart.png".

2. The Sample Data

The sample data is the deviation of the monthly average temperature from the average temperature of 1951-1980 means of the corresponding month for the North Hemisphere (land + ocean). It is taken from NASA's GISS Surface Temperature Analysis. Only rows corresponding to years 1987-2016 and columns corresponding to the 12 months are retained.

This script reads a csv file or a space-delimited tabulated matrix of numbers (e.g. generated by a spreadsheet program) and converts it into lines of the format: row_label column_label matrix_entry. An extra blank line is inserted after the last entry of each row. When fed as a data file to the "splot" command of gnuplot, this kind of file is interpreted as x-, y-, and z-coordinates, and the result is a (rugged) grid plot.

a 3-d grid plot drawn with gnuplot

Usage example: ./mat2list.pl -r '1987:' -c '1:' temperature.csv > rugged.txt It can also read from standard input: ./mat2list.pl -r '1987:' -c '1:' < temperature.csv > rugged.txt

The following command line options are available:

-c m:n column labels (x-coordinates) starts at m and increments by n for each column.

-r m:n row labels (y-coordinates) starts at m and increments by n for each row.

-d ':' input delimiter is ':' instead of ','

-t transpose the output. That is, output lines of the format instead: row_label column_label matrix_entry.

For -c and -r, the starting number is 0 if omitted, and the step number is 1 if omitted. Instead of a pair of colon-separated numbers, the argument to -r or -c can also be a list of space-separated numbers, directly specifying the labels themselves.

Suppose you have a data file rugged.txt (e.g. generated by mat2list.pl) consisting of lines of the format: x_coord y_coord z_coord where the x-coordinates and y-coordinates form a rectangular grid.

In order to create a column chart (3d version of a normal bar chart), we need to expand the data by converting every input line into 4 vertices of the same height (z-coordinate) that surround the original vertex. In general, each new vertex should be placed at the center of 4 original neighboring vertices. Some original vertices (i.e. those at the border of the plot) don't have neighbors and therefore the corresponding new vertices' x- and y-coordinates have to be guessed.

The pt2sq.pl script does this expansion by taking the -x and -y options that specify the x-spacing and y-spacing of the original data. These options default to 1.0 if they are missing. That is, pt2sq.pl does not infer the spacing from the input data.

Usage example: ./pt2sq.pl rugged.txt > colchart.txt It can also read from standard input: ./pt2sq.pl < rugged.txt > colchart.txt

Then you can splot "colchart.txt" inside gnuplot and get the column chart.

a column chart (3-d bar chart) drawn with gnuplot

colchart's People

Contributors

ckhung avatar

Watchers

James Cloos avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.