FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

docs: document variable color assignment for histogram components · gnuplot/gnuplot@09ef613 · GitHub

Repository navigation

Commit 09ef613

Browse files
Ethan A Merritt
committed
docs: document variable color assignment for histogram components
Add a section to the user manual. Add a corresponding example histogram_colors.dem to the demo collection.
1 parent e8e7576 commit 09ef613

3 files changed

Lines changed: 117 additions & 7 deletions

File tree

‎demo/all.dem‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -398,6 +398,7 @@ load "histograms.dem"
398398
load "histograms2.dem"
399399
load "histerror.dem"
400400
load "label_stacked_histograms.dem"
401+
load "histogram_colors.dem"
401402
reset
402403

403404
print "********************** file boxclusters.dem *********************"

‎demo/histogram_colors.dem‎

Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
#
2+
# Show how variable color can be used to histogram categorical data even
3+
# when the data sources are not completely parallel. Each data file
4+
# (datablock in this demo) contains a column with a category identifier
5+
# and a column with the data value contributing to the histogram.
6+
# However not all categories are present in each file, so they are not
7+
# parallel in that the Nth line of two files may or may not belong to
8+
# the same category.
9+
# Therefore gnuplot's automatic color assignment would fail.
10+
# Instead we use the category identifier to assign colors.
11+
#
12+
$Set1 << EOD
13+
A 15
14+
B 21
15+
C 12
16+
D 9
17+
G 15
18+
L 12
19+
EOD
20+
$Set2 << EOD
21+
B 14
22+
C 12
23+
D 16
24+
E 8
25+
G 14
26+
H 19
27+
I 20
28+
EOD
29+
$Set3 << EOD
30+
D 13
31+
E 7
32+
F 14
33+
G 11
34+
H 15
35+
I 4
36+
L 11
37+
EOD
38+
39+
unset border
40+
set tics nomirror
41+
unset ytics
42+
set boxwidth 0.8
43+
set key lmargin maxcol 1 invert
44+
set key title " Category "
45+
46+
# Set up a range of 12 defined linetype colors
47+
set for [i=1:8] linetype 100+i lc i # copy the default 8 colors
48+
set linetype 109 lc "gray50" # then add a few more
49+
set linetype 110 lc "white"
50+
set linetype 111 lc "orchid"
51+
set linetype 112 lc "seagreen"
52+
53+
alphabet = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
54+
color(category) = 100 + strstrt(alphabet, category)
55+
56+
set style data histogram
57+
set style histogram columns
58+
set style fill solid border lc "black"
59+
60+
set title "Column-stacked histogram colored by data category"
61+
62+
plot for [data in "$Set1 $Set2 $Set3"] \
63+
data using 2:(color(strcol(1))) lc variable title data, \
64+
for [i=1:12] keyentry with boxes lc color(alphabet[i:i]) title alphabet[i:i]
65+
66+
pause -1 "<cr> to continue"
67+
68+
reset

‎docs/gnuplot.doc‎

Lines changed: 48 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -406,6 +406,7 @@ C
406406
#b Change: Text rotation angle is not limited to integral degrees.
407407
#b Special (non-numerical) linetypes `lt nodraw`, `lt black`, `lt bgnd`
408408
## See `special_linetypes`.
409+
#b Data-driven color assignments in histogram plots. See `histograms colors`.
409410
#end
410411

411412
3 Features introduced in version 5.4
@@ -5437,7 +5438,8 @@ Ffigure_histeps
54375438
corresponding to the second entry in the respective data columns, and so on.
54385439
The default gap width of 2 indicates that the empty space between clusters is
54395440
equivalent to the width of 2 boxes. All boxes derived from any one column
5440-
are given the same fill color and/or pattern (see `set style fill`).
5441+
are given the same fill color and/or pattern; however see the subsection
5442+
`histograms colors`.
54415443

54425444
Each cluster of boxes is derived from a single row of the input data file.
54435445
It is common in such input files that the first element of each row is a
@@ -5470,10 +5472,10 @@ Ffigure_histeps
54705472

54715473
The `columnstacked` style is similar, except that each stack of boxes is
54725474
built up from a single data column. Each data value from the first specified
5473-
column yields a box in the stack at x=1, each data value from the second
5474-
specified column yields a box in the stack at x=2, and so on. In this style
5475-
the color of each box is taken from the row number, rather than the column
5476-
number, of the corresponding data field.
5475+
data column yields a box in the stack at x=1, each data value from the second
5476+
specified data column yields a box in the stack at x=2, and so on.
5477+
In this style the color of each box is taken from the row number, rather than
5478+
the column number, of the corresponding data field.
54775479

54785480
Box widths may be modified using the `set boxwidth` command.
54795481
Box fill styles may be set using the `set style fill` command.
@@ -5613,6 +5615,47 @@ Ffigure_newhist
56135615

56145616
set style histogram columnstacked
56155617
plot for [i=3:8] "datafile" using i title columnhead
5618+
3 histogram color assignments
5619+
?with histograms colors
5620+
?histograms colors
5621+
The program assigns a color to each component box in a histogram
5622+
automatically such that equivalent data values maintain a consistent
5623+
color wherever they appear in the rows or columns of the histogram.
5624+
The colors are taken from successive linetypes, starting either with
5625+
the next unused linetype or an initial linetype provided in a
5626+
`newhistogram` element.
5627+
5628+
In some cases this mechanism fails due to data sources that are not
5629+
truly parallel (i.e. some files contain incomplete data). In other
5630+
cases there may be additional properties of the data that could be
5631+
visualized by, say, varying the intensity or saturation of their base
5632+
color. As an alternative to the automatic color assigmnent, you can
5633+
provide an explicit color value for each data value in a second `using`
5634+
column via the `linecolor variable` or `rgb variable` mechanism.
5635+
See `colorspec`. Depending on the layout of your data, the color category
5636+
might correspond to a row header or a column header or a data column.
5637+
Note that you will probably have to customize the key sample colors
5638+
to match (see `keyentry`).
5639+
5640+
Example: Suppose file_001.dat through file_008.dat contain one column with
5641+
a category identifier A, B, C, ... and a second column with a data value.
5642+
Not all of the files contain a line for every category, so they are not
5643+
truly parallel. The program would be wrong to assign the same color to the
5644+
value from line N in each file. Instead we assign a color based on the
5645+
category in column 1.
5646+
5647+
file(i) = sprintf("data_%03d.dat",i)
5648+
array Category = ["A", "B", "C", "D", "E", "F"]
5649+
color(c) = index(Category, strcol(c))
5650+
set style data histogram
5651+
plot for [i=1:8] file(i) using 2:(color(1)) linecolor variable
5652+
5653+
A more complete example including generation of a custom key is in the
5654+
demo collection
5655+
^ <a href="http://www.gnuplot.info/demo/histogram_colors.html">
5656+
histogram_colors.dem
5657+
^ </a>
5658+
56165659
2 image
56175660
?plotting styles image
56185661
?style image
@@ -5729,7 +5772,6 @@ Ffigure_impulses
57295772
2 columns: x y # line from [x,0] to [x,y] (2D)
57305773
3 columns: x y z # line from [x,y,0] to [x,y,z] (3D)
57315774

5732-
#TeX \newpage
57335775
2 labels
57345776
?plotting styles labels
57355777
?style labels
@@ -5783,7 +5825,6 @@ Ffigure_labels2
57835825

57845826
plot $Data using 1:2:3:4:5 with labels tc variable rotate variable
57855827

5786-
#TeX \newpage
57875828
2 lines
57885829
?plotting styles lines
57895830
?style lines

0 commit comments

Comments
 (0)

Back | FazBrowse Home | New Git URL