Plot Bar Charts Using Gnuplot (Part 3/3)
Parts one in addition to two of this serial illustrate how to purpose gnuplot to plot a two-dimensional betoken graph amongst time-series data. This post, the tertiary in addition to in conclusion of the series, focuses on plotting a bar chart.
The raw input information consists of the daily release of page views, in addition to clicks for this weblog from 2005 to 2014:
Date Page views Clicks 2005-08-01 nine 0 2005-08-02 65 1 <snipped> 2014-04-29 2862 x 2014-04-30 2256 2
My objective is to visualize if the solar daytime of the calendar week determines the sum of spider web traffic to this blog.
gnuplot is used to generate the next bar nautical chart amongst a engagement arrive at from Jan 1, 2014 to Apr 1, 2014.
The release of page views is plotted for each solar daytime inwards the engagement range. H5N1 unique color is used depending on the solar daytime of the week. Using the color cues from the inwards a higher house bar chart, nosotros tin conclude that Saturdays in addition to Sundays by in addition to large underperform equally compared to the residuum of the week.
The script for plotting the bar nautical chart is listed below in addition to it is likewise linked at https://bit.ly/1oeDsq1.
# Plot means gear upward means information boxes gear upward means fill upward corporation gear upward boxwidth 0.5 # Term type, background color, sail size gear upward terminal png background "#330000" \ size 1920, 960 \ font "/usr/share/fonts/truetype/msttcorefonts/Arial.ttf,18" # Output file get upward gear upward output "dayOfWeek.png" # Input information configuration # gear upward datafile separator "," # gear upward datafile missing "?" # Independent variable (X) = Time serial gear upward xdata fourth dimension gear upward timefmt "%Y-%m-%d" gear upward format x "%a %m-%d" # Specify subset engagement arrive at xstart="2014-01-01" xend ="2014-04-01" gear upward xrange [xstart:xend] # Define custom display styles gear upward means delineate of piece of job 1 lt 1 lc rgb "#FF9900" gear upward means delineate of piece of job 2 lt 2 lc rgb "#00FFFF" gear upward means delineate of piece of job iii lt iii lc rgb "#FFCC66" gear upward means delineate of piece of job four lt four lc rgb "#FF0000" gear upward means delineate of piece of job v lt v lc rgb "#FF00FF" gear upward means delineate of piece of job vi lt vi lc rgb "#0000FF" gear upward means delineate of piece of job vii lt vii lc rgb "#CC3300" gear upward means delineate of piece of job 8 lc rgb "#FFFFFF" # Axis tic marks gear upward xtics tc ls 8 rotate gear upward xtics xstart, 172800, xend gear upward ytics tc ls 8 gear upward bmargin 8 gear upward tics nomirror # Axis labels gear upward xlabel "Date" tc ls 8 offset -35, -3 gear upward ylabel "Page Views" tc ls 8 # Key (Legend) gear upward cardinal font "/usr/share/fonts/truetype/msttcorefonts/Arial.ttf,16" gear upward cardinal tc ls 8 gear upward cardinal exterior bottom horizontal # Misc. gear upward championship "Week of Day Stats" tc ls 8 gear upward grid gear upward edge lw 1 ls 8 # Plot plot "report.dat" every 7::2711 using 1:2 \ championship "Wed" ls 1, \ '' every 7::2712 using 1:2 \ championship "Thu" ls 2, \ '' every 7::2713 using 1:2 \ championship "Fri" ls 3, \ '' every 7::2714 using 1:2 \ championship "Sat" ls 4, \ '' every 7::2715 using 1:2 \ championship "Sun" ls 5, \ '' every 7::2716 using 1:2 \ championship "Mon" ls 6, \ '' every 7::2717 using 1:2 \ championship "Tue" ls vii
Below, I highlight the cardinal differences betwixt the inwards a higher house bar nautical chart script in addition to the points graph script inwards part 1. Please refer to the explanation inwards part 1 for the mutual elements. The official gnuplot user manual is likewise a adept resource.
Plot style
gear upward means information boxes gear upward means fill upward corporation gear upward boxwidth 0.5
- The plot means is boxes.
- The boxes are filled amongst solid colors.
- The box width is gear upward to a pocket-size value inwards fellowship to plot iii months worth of data.
Time-series variable
The tic grade labels on the "x" axis similar a shot include the solar daytime of the calendar week (%a).gear upward format x "%a %m-%d"
Custom delineate of piece of job styles
gear upward means delineate of piece of job 1 lt 1 lc rgb "#FF9900" gear upward means delineate of piece of job 2 lt 2 lc rgb "#00FFFF" gear upward means delineate of piece of job iii lt iii lc rgb "#FFCC66" gear upward means delineate of piece of job four lt four lc rgb "#FF0000" gear upward means delineate of piece of job v lt v lc rgb "#FF00FF" gear upward means delineate of piece of job vi lt vi lc rgb "#0000FF" gear upward means delineate of piece of job vii lt vii lc rgb "#CC3300" gear upward means delineate of piece of job 8 lc rgb "#FFFFFF"
- Seven custom delineate of piece of job styles - indexed 1 to vii - are defined, i per each solar daytime of the week.
- Line means 8 is created for labels, grid lines, in addition to borders.
X axis tics
gear upward xtics xstart, 172800, xend
The triplet xstart, 172800, xend specifies the scale of the "x" axis. Specifically, the "x" axis labels arrive at from 2014-01-01 (xstart) to 2014-04-01 (xend) incrementing every 2 days (or 172800 seconds).
Key (Legend)
gear upward cardinal exterior bottom horizontal
The legend is moved to the bottom in addition to outside of the plot area. In addition, instead of stacking the keys vertically, they are set out horizontally.
Plot
plot "report.dat" every 7::2711 using 1:2 \ championship "Wed" ls 1, \ '' every 7::2712 using 1:2 \ championship "Thu" ls 2, \ '' every 7::2713 using 1:2 \ championship "Fri" ls 3, \ '' every 7::2714 using 1:2 \ championship "Sat" ls 4, \ '' every 7::2715 using 1:2 \ championship "Sun" ls 5, \ '' every 7::2716 using 1:2 \ championship "Mon" ls 6, \ '' every 7::2717 using 1:2 \ championship "Tue" ls vii
- vii plots are defined, each assigned to a unique delineate of piece of job means (ls).
- All vii plots describe from the same input information file report.dat.
- To specify how input information is distributed to the vii plots, you lot need to await upward the starting fourth dimension solar daytime of your target engagement arrive at (January 1, 2014) inwards the input information file. It happens to hold upward delineate of piece of job 2712. As a result, all vii plots skip the starting fourth dimension 2711 lines inwards the input file.
- The starting fourth dimension plot starts at delineate of piece of job 2712 of the input file, in addition to skips ahead every vii days(every 7::2711). Note that, because delineate of piece of job numbers are 0-based, it is specified equally 2711 inwards the every clause.
- Jan 1 is a Wed which is explicitly specified equally the title of the starting fourth dimension plot.
- Each subsequent plot starts at i delineate of piece of job below its predecessor. Therefore, plot 2 starts at delineate of piece of job 2713 (but specified equally 2712 inwards every 7::2712).
0 Response to "Plot Bar Charts Using Gnuplot (Part 3/3)"
Post a Comment