I have a CSV file with a data, and I need to plot a histogram (bars actually) using the data from given file. However, labels at axis X need to have Polish letters, for instance ąęćżźśłóń (or, uppercase, ĄĘĆŻŹŚŁÓŃ). I have already set the encoding with set encoding iso_8859_1 but still, the result does not look like what I want:
Here is my gnuplot script:
#!/usr/bin/gnuplot
set encoding iso_8859_1
set datafile separator "\t"
set termoption enhanced
set terminal postscript eps size 5.5, 5.62 enhanced color font 'Verdana,20' linewidth 2
set output '2008.eps'
unset key
set xtics nomirror rotate by -45 scale 0 font ",15"
set style data histogram
set boxwidth 0.2
set grid y
set yrange [ * : 20000]
set style fill solid border
plot '2008.csv' using 2:xticlabels(1) with boxes linecolor rgb "#00FF00", \
'' using 0:2:2 with labels center offset 0,1 notitle
And my data file:
Województwo Suma
Dolnośląskie 4997 4997
Kujawsko-Pomorskie 10710 10710
Lubelskie 8978 8978
Lubuskie 4631 4631
Łódzkie 12609 12609
The question is: what do I need to do to have Polish letters on axis X, and in a plot title (which is not available here, but I would like to add it later)? Thank you.
You should probably use UTF-8. Here's what I did:
set terminal epscairo enhanced color dashed rounded size 5.5, 5.62
set encoding utf8
set output '2008.eps'
unset key
set xtics nomirror rotate by -45 scale 0 font ",15"
set style data histogram
set boxwidth 0.2
set grid y
set yrange [*:20000]
set style fill solid border
plot '2008.csv' using 2:xticlabels(1) with boxes linecolor rgb "#00FF00", \
'' using 0:2:2 with labels center offset 0,1 notitle
(I copied the data from your question, which is in UTF-8 format but doesn't contain tab characters, so I didn't use set datafile separator "\t".)
This gave me the following result.
I'm using the epscairo terminal because it uses the pango library for rendering text which is based on UTF-8.
Related
I am trying to set the color of a character-defined point type in gnuplot. Although I can select the desire color of a system defined point type, I cannot do the same with the character-defined one. Below I present a minimal example.
set samples 5
set term pdf
set o "mwe.pdf"
p x with points lt rgb "violet" pt "V",\
x with points lt rgb "violet" pt 2
set o
The result looks like this:
I also tried to set the color with the lc variable method and feeding the keyword using with a column ("#005893"), buit it still doesn't change the color.
Question
How can I set the color of the letter to achieve something like this:
the following works for me.
reset session
set samples 5
plot x with points pt "V" tc rgb "red" font ",20", \
x with points lt rgb "red" pt 2 ps 3
Result:
Character point types are rendered by the same driver routine that handles labels and other text. Therefore the color is taken from the current font and font properties apply, including color:
set sample 11
plot sin(x) with point pointtype "µ" textcolor rgb "violet" font "/:Bold,15"
You should use textcolor instead of linecolor or linetype to change the point type defined by a character, as others pointed out already. See the gnuplot documentation.
Gnuplot default range for polar coordinates is 0-360. Is it possible to change this default, and if so where?
Polar coordinates are interpreted as [t;r]. The default range of the independent variable t (trange) is [0:2pi], or if you have previously said set angle degrees then trange defaults to [0:360]. The default is just that, a default. You can set the range to anything you like before plotting. If you want tic labels for t and r you may need to set the tic range to match. If you plan to use these same settings for many plots, you might put some subset of the preparatory commands in your ~/.gnuplot startup file or in a configuration file that can be loaded prior to plotting load "polar_layout.gp"; plot t
set polar
set angle degrees
set trange [-180:180]
# turn off x/y border and labels
unset border; unset tics
# turn on polar border and axis labels as needed
set border polar
set grid polar
set ttics -150,30,150
set rtics 30
# aspect ration of plot (a circle should look circular)
set size square
plot t
I have a file with two columns
9 5
10 3
11 0
12 25
13 50
14 80
etc
What is the best way to plot bar char using gnuplot? Is using subprocess with gnuplot the best way? Ideally the graph should be in .pdf and in png as I want to put these on a website later on.
I would really appreciate your input/advise.
Here is an example, how to plot a bar chart with gnuplot using the plotting style with boxes
set terminal pngcairo size 1000,800 font ',12'
set output 'output.png'
set xlabel 'xlabel' font ',18'
set ylabel 'ylabel' font ',18'
set boxwidth 0.9
set style fill solid 0.3
set offset 0.5, 0.5, 10, 0
plot 'data.txt' with boxes linewidth 3 title ''
With the data you showed, this gives the following output image:
I'm trying to print stacked histogram from gnuplot into black and white png. By this I mean I would like each region in the bar to be hatched or checked alongside the legend on the side; that way when it's printed people can still identify the regions.
I've tried the following but it just leaves me with big black blobs!
set term pngcairo mono size 750, 300
set output \"pies/interesting.png\"
set style data histograms
set style histogram rowstacked
set boxwidth 1 relative
set style fill solid 1 border -1
set yrange [0:100]
set ytics 10
set datafile separator \",\"
plot './functions-$MODE.csv.t' using 1 t \"\", for [i=9:13] '' using (100.*column(i)/column(15)) ti column(i)
How do I make my regions hatched?
Apologies for answering my own question....I've realised that a stacked histogram behaves like a normal histogram: thus if I use the styles found on this page: http://gnuplot.sourceforge.net/demo/fillstyle.html I can customise to how I would like: setting "set style fill pattern border" :
set term pngcairo mono size 750, 300
set output \"pies/interesting.png\"
set style data histograms
set style histogram rowstacked
set boxwidth 1 relative
set style fill pattern border
set datafile separator \",\"
plot './functions-$MODE.csv.t' using 1 t \"\", for [i=9:13] '' using (100.*column(i)/column(15)) ti column(i)
Results in the desired effect.
Log plots in MATLAB only label the axes at positions 10^x, where x is an integer (e.g., 10^4, 10^5, 10^6). Sometimes, one may want labels at intermediate sites or minor ticks (e.g., 5*10^4, 5*10^5).
In order to place such labels, I have resorted to using the text command with appropriate x and y coordinates. However, the font of the superscript in the text command differs from that in the default axis label. This is true even if the font for axis label and text is set to be identical by the following:
set(0,'DefaultAxesFontName','Helvetica');
set(0,'DefaultTextFontName','Helvetica');
set(0,'DefaultTextFontSize',15);
set(0,'DefaultAxesFontSize',15);
In particular, the superscript font size appears to be smaller in the default axis label compared to the text box. Is there a way to resolve this discrepancy so that the font in the text box and the font in the axis label are identical (including superscripts)?
You can set the x and y axis points like this:
figure
set(gca,'xtick',10.^[0.5:0.5:3])
set(gca,'ytick',10.^[0.5:0.5:3])
gives you steps in 0.5 log 10. There is also an attribute called xticklabel
EDIT: Here's a complete example using arbitrary labels, scientific notation:
semilogx([2:100:10e4],[2:100:10e4])
axis([2 2e4 2 10000])
xticks=10.^[0.5:0.5:10]';
al={};
for i = 1:length(xticks)
tmps=sprintf("%1.1e}",xticks(i));
tmps=strrep(tmps,"e","x10^{"); # replace e with x10^{
tmps=strrep(tmps,"+0",""); # +0 does not add any info
tmps=strrep(tmps,"-0","-"); # -0123 into -123
tmps=strrep(tmps,"+",""); # + does not add any info
al(i)=tmps;
end
set(gca,'xtick',xticks);
set(gca,'xticklabel',al)