Can't visualize dots in Chart::Gnuplot graph legend - perl

I'm hoping someone can help me figure out what is either wrong or possible when plotting a chart using Chart::Gnuplot module and 'dots' in Perl.
Here is what I have for my dataset:
# RFE Chart object
my $chart_RFE = Chart::Gnuplot->new(
output => $out_file_RFE,
terminal => "png",
title => {
text => "Step ROCOF",
font => "arial, 12",
},
xlabel => $chart_xlabel,
ylabel => "ROCOF Error (Hz/s)",
legend => {
position => "outside top",
align => "left",
},
);
# RFE Dataset
$dataSet = Chart::Gnuplot::DataSet->new(
xdata => \#dataX,
ydata => \#dataY,
style => 'dots',
color => $COLORS[3],
title=> 'RFE',
);
I want the dots because I have lot of data points to graph. However, the legend of the graph it produces shows no dots next to the legend names. If I change style to 'points'
style => 'points',
the different points show up in the graph's legend. Is there a way to get the dots to show? I've zoomed in on the legend area wondering if maybe they were just small but nothing shows up. I've also tried setting the width => option but that doesn't do anything (as I suspect it wouldn't since it's for lines).
Anyone know if this is even possible?

There's no option to change the point size in the legend (or "key," as Gnuplot calls it) so you have to use a hack to achieve the desired effect.
First, plot your dataset using the dots style, but don't assign it a title; then plot a dummy dataset using a different style and assign a title:
use strict;
use warnings;
use Chart::Gnuplot;
my #x = map { rand } 0 .. 10_000;
my #y = map { $_ + 0.1 - rand 0.2 } #x;
my $chart = Chart::Gnuplot->new(
output => 'gnuplot.png',
legend => {
position => 'outside top',
align => 'left'
}
);
my $color = '#ff0000';
my $dataset = Chart::Gnuplot::DataSet->new(
xdata => \#x,
ydata => \#y,
style => 'dots',
color => $color
);
my $dummy = Chart::Gnuplot::DataSet->new(
ydata => [ 'inf' ],
style => 'points',
pointtype => 'fill-circle',
pointsize => 1,
title => 'foo',
color => $color
);
$chart->plot2d($dataset, $dummy);
Output:
Note that this has been asked elsewhere for the command line version of Gnuplot, but it's actually pretty difficult to create a dummy dataset that plots nothing with Chart::Gnuplot. Using a y-value of "inf" was the only thing I could get to work that didn't require knowing the range of your axes.

Related

Image crop aspect ratio do not works

Trying to figure out the image crop aspect ratio attribute, but can't make it working.
The code isL
protected function addUserFields()
{
$this->crud->addFields([
[
'name' => 'profile_image', // The db column name
'label' => trans('Profile image'), // Table column heading
'type' => 'image',
'upload' => true,
'crop' => true,
'aspect-ratio' => 1,
]);
}
It’s probably because you’re using a dash instead of underscore. It should be:
'aspect_ratio' => 1, // omit or set to 0 to allow any aspect ratio
Please also note what the docs say:
The value for aspect_ratio is a float that represents the ratio of the cropping rectangle height and width. By way of example,
Square = 1
Landscape = 2
Portrait = 0.5
And you can, of course, use any value for more extreme rectangles.

Perl checkbox group subgroupings

I'm trying to make a checkbox group in Perl with sub-titles dividing certain checkboxes. All the checkboxes are related, but they are in subcategories that I would like to be displayed when the user is selecting their choices.
my $grocery_list = $q->checkbox_group(
-name=>'grocery_list',
-values=>\#items,
-linebreak=>'true',
-labels=>\%items,
In the above example, I might have 'Milk' and 'Cheese' be under the subcategory of "DAIRY", while 'Ham' and 'Turkey' are under the subcategory of "MEATS". I already have a checkbox group with my values but I'm struggling creating those subcategory titles (DAIRY and MEATS) in between the subgroups of checkboxes. Ideally, the subcategory titles wouldn't be checkboxes, but would just divide checkboxes. Is it possible to put these subdivisions in a single checkbox, or would I have to make multiple checkboxes and merge the checked items into a single array afterward?
Note that CGI is no longer considered to be best practice. You should read CGI::Alternatives for an explanation, as well as suggestions for alternative modules.
You need the fieldset and legend elements to do what you describe. Without any additional CSS, the former draws a box around the group of inputs that it contains, and the latter labels that box.
Unfortunately, the checkbox_group convenience method doesn't allow you to subdivide its elements between two field sets, so you will have to call it twice with the same parameters except for the values and labels. It may be better to write your own helper routine that calls checkbox directly to build appropriate grouping.
Here's the basic idea. There's nothing magical about the CGI methods -- they just generate HTML according to the parameters you pass.
my %labels = (
milk => 'Milk',
cheese => 'Cheese',
ham => 'Ham',
turkey => 'Turkey',
);
my #dairy_items = qw/ milk cheese /;
my #meat_items = qw/ ham turkey /;
my $dairy = $q->checkbox_group(
-name => 'grocery_list',
-values => \#dairy_items,
-linebreak => 'true',
-labels => \%labels,
);
my $meat = $q->checkbox_group(
-name => 'grocery_list',
-values => \#meat_items,
-linebreak => 'true',
-labels => \%labels,
);
print
$q->start_form,
$q->fieldset(
$q->legend('Dairy'),
$dairy,
),
$q->fieldset(
$q->legend('Meat'),
$meat,
),
$q->end_form;

Solid Lines with Different colors using Gnuplot in Perl

I am trying to create a chart with two conditions :-
1) Solid lines
2) Different colors .
Here is my code snippet :-
my $set = Chart::Gnuplot::DataSet->new(
xdata => "words",
ydata => "bits",
title => "wordsvsbits",
type => "matrix",
font => "arial, 20",
width => 7,
style => "linespoints",
linetype => "solid",
imagesize => "1.5,1.5",
);
When i do this , I get solid lines with only one colour . If I dont give linetype ,
1st line is a solid (Red color), 2nd line is dashed with different color and 3rd line is also dashed with a new color .
Here I want to get new color for each line , but they should all be solid lines .
Kindly , please help me .
Until version 4.6. this is controlled by set termoption solid. In Perl this should work with
my $chart = Chart::Gnuplot->new(
termoption => "solid",
);
and without specifying the linetype.

Perl: GD:SecurityImage, angle property not working

I am trying to create a Security Image from a text using the perl module GD:SecurityImage with the following object:
my $image = GD::SecurityImage->new(
width => 220,
height => 60,
lines => 5,
scramble => 1,
angle => 45,
gd_font => 'giant',
);
$image->create( normal => 'circle' );
$image->particle(30, 70);
But the text in resulted image doesn't have the text angled at 45 Degrees rather its random.
Also if i make scramble = 0 and have angle = 45, the text doesn't rotate at that angle, text is just default in the image as seen in the attach screen.
Please help me out, what am i doing wrong here?.
NOTE: Image is with scramble = 0;
Please note that you must have Math::Trig to rotate with GD, otherwise you get no rotation. You don't need that with the ImageMagick backend - try that. (And use TTF :))

How do I keep GD::Graph from showing points outside of the graphing area?

I am making some plots in Perl using GD::Graph and some of the data is outside the area I would like to display, but instead of being truncated off the chart outside the graphing area, it is being drawn over the title, legend, and axis labels. Does anyone know how to stop this from happening?
If you know what your bounds are, filter the data and don't include those points in the data that you send to GD::Graph.
To clarify: are you declaring the y_max_value height and your data is overflowing that bound? Or is GD::Graph miscalculating the correct upper limit?
If you're setting the value, you need to fix your values to that upper bound. GD::Graph is only doing what you're telling it to do. (Which is more or less what Brian said).
OTOH, I've found that GD::Graph doesn't always cope well with cumulative (stacked) graphs, and tends to overestimate the y_max_value in those circumstances. It can also produce some unattractive values on the Y axis, with floating point numbers at the tick values. Is this what you're really trying to solve?
Having had both these problems, we've found a solution using Tie::RangeHash to create 'tidy' increments that always produce 5 integer tick points.
use Tie::RangeHash ;
my $y_ranges = new Tie::RangeHash Type => Tie::RangeHash::TYPE_NUMBER;
$y_ranges->add(' -500, -101', '-25');
$y_ranges->add(' -100, -26', '-10');
$y_ranges->add(' -25, -1', '-5');
$y_ranges->add(' 0, 25', '5');
$y_ranges->add(' 26, 100', '10');
$y_ranges->add(' 101, 500', '25');
$y_ranges->add(' 501, 1000', '100');
$y_ranges->add(' 1001, 5000', '250');
$y_ranges->add(' 5001, 10000','1000');
$y_ranges->add('10001, 50000','2500');
$y_ranges->add('50001,' ,'5000');
sub set_y_axis {
# This routine over-rides the y_max_value calculation in GD::Graph, which produces double the
# required limit, and therefore a lot of white-space...
return 1 unless #_ ; #no point going any further if no arguments were provided, however result has to be
#non-zero to avoid /0 errors in GD::Graph
my #a = map { $_ || 0 } #_ ; #array may have undefs in it. Set null to zero for calc of max
my ($y_max) = sort { $b <=> $a } #a ; # Get largest total for y-axis
my $y_range = $y_ranges->fetch($y_max);
my $y_axis = ($y_max%$y_range==0) ? $y_max+$y_range : ($y_max - ($y_max%$y_range) + $y_range);
sprintf("%d", $y_axis);
}
sub my_graph {
my #ymax;
# generate data... foreach loop etc
push(#ymax, $this_y_value); # append y-value or cumulative y-value as appropriate
# etc.
my $graph = GD::Graph::lines->new(750, 280);
$graph->set(
y_max_value => set_y_axis(#ymax),
x_labels_vertical => 1,
transparent => 1,
# etc
);
# etc
}
Hope that's useful to you.