Skip to content

Commit dae0d65

Browse files
committed
add documentation to UTF-8 encode text labels etc - fix #74
1 parent 7c1df16 commit dae0d65

File tree

2 files changed

+26
-0
lines changed

2 files changed

+26
-0
lines changed

CHANGES

+1
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
- fix plot3d array-ref handling (#87) - thanks @djerius for report
77
- fix gplot array-ref handling (#86) - thanks @djerius for report
88
- add multiplot_next to skip one plot (#85)
9+
- add documentation to UTF-8 encode text labels etc (#74) - thanks @zmughal for report
910

1011
2.024 2023-03-30
1112
- Add Alien::Gnuplot as a configure-time dependency. Fixes #92 - thanks @zmughal

lib/PDL/Graphics/Gnuplot.pm

+25
Original file line numberDiff line numberDiff line change
@@ -288,6 +288,31 @@ Backslash escapes control characters to render them as themselves.
288288
289289
=back
290290
291+
=head2 Unicode text
292+
293+
Separately to "enhanced" text above, if you wish to include text that
294+
is not ASCII, then you will need to pass data that has been UTF-8
295+
encoded. Sample code to achieve this:
296+
297+
use utf8;
298+
use Encode;
299+
use PDL;
300+
use PDL::Graphics::Gnuplot;
301+
use PDL::Constants qw(PI);
302+
303+
sub plot_sin {
304+
my ($w, $coeff) = @_;
305+
my $xrange = [ -2*PI, 2*PI ];
306+
my $x = zeroes(1e3)->xlinvals(@$xrange); my $y = sin($coeff * 2 * PI * $x);
307+
my $title = "y = sin( $coeff * 2π * x )";
308+
# to get around sending text through syswrite()
309+
my $title_octets = encode('UTF-8', $title);
310+
$w->plot(with=>'lines', $x, $y, {
311+
xrange => $xrange,
312+
title => $title_octets, # can not pass $title as-is
313+
});
314+
}
315+
291316
=head2 Color specification
292317
293318
There are several contexts where you can specify color of plot elements. In those

0 commit comments

Comments
 (0)