gnuplot - cannot place the key using the at-attribute - bar-chart

I have this "MWE"
set title font "Monospaced,13" 'Total duration'
set grid
set style data histograms
set style histogram cluster
set style fill solid
set xtics format ""
set grid ytics
set ylabel "Milliseconds"
AddFirstColor = "#491d75";
AddLastColor = "#b32929";
RemoveFirstColor = "#d49435";
RemoveLastColor = "#12520b";
set yrange[0:16000]
set ylabel "Milliseconds"
set key at 1.9,2.5 opaque box lc "black" linewidth 3 spacing 1.2 box opaque fillcolor "grey"
plot 'data.dat' using 2:xtic(1) title "Add first" linecolor rgb AddFirstColor, \
'' using 3 title "Add last" linecolor rgb AddLastColor, \
'' using 4 title "Remove first" linecolor rgb RemoveFirstColor, \
'' using 5 title "Remove last" linecolor rgb RemoveLastColor, \
'' u 0:1:1 with labels offset -6.0,-100.0 title ""
set terminal png size 650,350 enhanced font "Monospaced,13"
set output 'data.png'
replot
exit
The data.dat contains:
# AddFirst AddLast RemoveFirst RemoveLast
"Linked list" 6841 6675 1189 1042
"Circular list" 7037 9703 2546 2332
The output is:
I wish to place the key box on top right such that it is (say) 5 pixels from the top line of the plot and 5 pixels from the right verical line. How could I achieve that?
Edit: extending the question
Now I have two graphs:
AddAtBeginning.png:
and
As you can see, the key box is anchored to the left top corner differently in the above two graphs: the horizontal distances from the key box and the y-axis do not match. I need to make them equidistant. (I suppose it is due to the fact that the two plots have the y-label area of different sizes, since we are dealing with different scales.) Also, it would be nice if the plot boxes had similar geometry (same dimensions, same position relative to entire .png file) (this might or might not solve my issue automatically).
AddAtBeginning.plt is given by:
set xlabel 'Size'
set ylabel 'Microseconds'
set xrange [0:1000000]
plot 'AddAtBeginning.dat' index 0 title "Array list", \
'' index 1 title "Indexed list", \
'' index 2 title "Linked list", \
'' index 3 title "Tree list
set terminal png background rgb "grey" size 650,350 enhanced font "Monospaced,13"
set output 'AddAtBeginning.png'
set style rect fc rgb "white" fs
set object 1 rectangle from screen 0,0 to screen 1,1 behind
set key at graph 0.425,0.97 box lt -1 lw 2 opaque
replot
exit
Also, AddAtEnd.plt is given by:
set xlabel 'Size'
set ylabel 'Microseconds'
set xrange [0:1000000]
plot 'AddAtEnd.dat' index 0 title "Array list", \
'' index 1 title "Indexed list", \
'' index 2 title "Linked list", \
'' index 3 title "Tree list
set terminal png background rgb "grey" size 650,350 enhanced font "Monospaced,13"
set output 'AddAtEnd.png'
set style rect fc rgb "white" fs
set object 1 rectangle from screen 0,0 to screen 1,1 behind
set key at graph 0.425,0.97 box lt -1 lw 2 opaque
replot
exit
In the above image, I need to anchor the red area statically to the entire .png file (the green box) dimensions, and I need to anchor the violet key box statically relative to the red graph border.

Please always check gnuplot help before asking questions! There is to almost every keyword an entry help <keyword>.
Here, it would have been help key or in newer versions help key placement.
There are different coordinate systems, check help coordinates, but as far as I know no pixel coordinate system.
But something like the following should do the job:
set key at graph 0.995,0.99
Addition:
That's what I finally understood from your revised question: you want place the key box in a fixed (pixel) distance from a corner of a graph, independent of the graph size. If your x-range is the same for all graphs you could use first for the x-position and graph for the variable y-range.
Although, depending on the y-labels and y-tics, you could also set the same left margin and ensure the same size and aspect ratio for all plots. Then graph coordinates would be constant and independent of x- and y-range.
There is also a way to set it in a fixed pixel distance independent of graph size and x,y-ranges. However, this would be a cumbersome solution requiring replotting. If you're really interested let me know.
Script:
### place legend box at distance from corner "almost" independent of graph size
reset session
set key left box width 1
set key at first 10000, graph 0.97
set tics out
set multiplot layout 2,1
set xrange[0:1e6]
set yrange[0:10]
set ylabel "some label"
plot 1e-5*x, 2e-5*x, 3e-5*x w l
set yrange[0:1000000]
set ylabel "some multiline\nlabel\n with 3 lines" offset -1.5,0
plot x, 2*x, 3*x w l
unset multiplot
### end of script
Result:
Addition 2:
So, after all, it seems you were just looking for constant margins for all graphs, e.g. set margins 20,5,10,10, check and read help margins. If the graphs have the same size, the position of your key box will be identical if you use graph coordinates. I hope, this will answer your question unless you have another unmentioned requirement.
Script:
### place legend box at distance from corner
reset session
set key left box width 1
set key at graph 0.01, graph 0.97
set tics out
set margins 20,5,10,10 # l,r,b,t
set multiplot layout 2,1
set xrange[0:1e6]
set yrange[0:10]
set ylabel "some label"
plot 1e-5*x, 2e-5*x, 3e-5*x w l
set yrange[0:1000000]
set ylabel "some multiline\nlabel\n with 3 lines" offset -1.5,0
plot x, 2*x, 3*x w l
unset multiplot
### end of script
Result:

Related

How to crop features outside an image region using pytorch?

We can use ROI-Pool/ROI-Align to crop the sub-features inside an image region (which is a rectangle).
I was wondering how to crop features outside this region.
In other words, how to set values (of a feature map) inside a rectangle region to zero, but values outside the region remains unchanged.
I'm not sure that this idea of ROI align is quite correct. ROI pool and align are used to take a number of differently sized regions of interest identified in the original input space (i.e. pixel-space) and output a set of same-sized feature crops from the features calculated by (nominally) the convolutional network.
As perhaps a simple answer to your question, though, you simply need to create a mask tensor of ones with the same dimension as your feature maps, and set the values within the ROIs to zero for this mask, then multiply the mask by the feature maps. This will suppress all values within the ROIs. Creation of this mask should be fairly simple. I did it with a for-loop to avoid thinking but there's likely more efficient ways as well.
feature_maps # batch_size x num_feature maps x width x height
mask = torch.ones(torch.shape(feature_maps[0,0,:,:]))
for ROI in ROIs: # assuming each ROI is [xmin ymin xmax ymax]
mask[ROI[0]:ROI[2],ROI[1]:ROI[3]] = 0
mask = mask.unsqueeze(0).unsqueeze(0) # 1 x 1 x width x height
mask = mask.repeat(batch_size,num_feature_maps,1,1) # batch_size x num_feature maps x width x height
output = torch.mul(mask,feature_maps)

How to change colors of a boxplot in octave?

I want to plot 9 distributions using boxplot in Octave. In order to make it more readable, I expected to able to change the inner colour of boxes, or the blue line surrounding it.
Looking at the source code, I realize that colours are hardcoded.
A matlab solution would be1:
a = get(get(gca,'children'),'children'); % Get the handles of all the objects
t = get(a,'tag'); % List the names of all the objects
box1 = a(7); % The 7th object is the first box
set(box1, 'Color', 'g'); % Set the color of the first box to green
Is there a similar procedure for octave? Or any other hints?
thanks in advance,
alan
Actually you are almost there. The following works for me for a single boxplot:
b = boxplot(data);
c = get(gca,'children');
for i=1:size(c)
set(c(i), 'color', 'g');
end
The above snippet colors the whole boxplot green. You can set the color of the individual c(i)'s to your liking.

Double scale for CSV data in gnuplot

I would like to plot CSV data, and refer them with two x-axes. On the bottom linear (4*$1^2) scale, and on the top - logarithmic scale in other units ($1). Both scales should refer to the same plot.
plot "sum_no_realloc.csv" using ($1*$1*4):4 with lines,
So the bottom scale should be in 4*$1^2 units, and the top should be in $1 units.
Use the link command.
Suppose that your data file looks like this:
3 1
4 2
10 3
20 4
and you want to plot as you described. The x2 axis needs to show the x-coordinates and the x1 axis needs to show the transformed coordinates.
Issue the following commands:
set link x2 via sqrt(x/4.0) inverse 4.0*x*x
set x2tics
Then if you plot by
plot "datafile.txt" using ($1*$1*4.0):2 with lines
You will see that the x2 axis runs from 0 to 20 and the x1 axis runs from 0 to 1600 (4*20*20). The link command forces the two axes to be linked based on a mapping function. You need to specify how the x2 axis is determined from the x1 axis and how to go the other way around as well - gnuplot will usually throw a warning message when you do this about not being able to confirm the mapping.
The following plot shows the results (I labeled the axes using the normal set xlab and set x2lab commands).

gnuplot graph misplaced on canvas

I need to have a graph in a specific format. I am using Gnuplot and try to use the size and terminal size to change the size of my output. However, Gnuplot does some really weird stuff and I don't know how to change things...
I am using Gnuplot Version 4.4 Patchlevel 3.
Here is a minimal example:
reset
set size 1
set terminal postscript enhanced color solid linewidth 1 size 15cm,10.5cm font "Helvetica" 16
set output "C:/..."
set encoding iso_8859_1 #for special characters
set xrange [2.05:3.13] #2. Achse
set yrange [1.5:2.1]
set border 3
set key spacing 1.5
set pointsize 0.6
plot '[...].dat' using 1:2 notitle with points pt 7 lc rgb "#000000" pointsize 1
that gets me the following output: http://i.stack.imgur.com/Z78gF.jpg
The graph is halved in size and starts in the middle of the canvas. I cannot change the position by using margins... I thought it might be a problem of size so I set set size 2 which then gave me http://i.stack.imgur.com/Ov5Ha.jpg . The graph still starts in the middle left and extends way over the boundaries, while most of the canvas stays white...
I have no idea what's going on and tried all kinds of stuff, but still, the picture won't start in the bottom left corner but somewhere in the middle, being shrinked in size... Somebody had the same problem?
I just want to get a Gnuplot figure of the size 15 cm x 10.5 cm - it can't be that difficult, can it be?
Thanks a lot!
After some messing aroung with gsview and gnuplot I found a solution that works for me that includes basically 4 steps:
1) use eps or even postscript, it doesn't really matter. Do not use the set size command. I used eps and it looks very good, here is one proposition:
set terminal postscript eps enhanced color solid linewidth 1 size 15cm,10.5cm font "Helvetica" 22
leave the ret as it was and go to
2) GSView: First check "Options - Show Bounding Box".
Use the commands under "Orientation" to orient canvas and figure so they match each other. This is usually landscape!
Now enter "Media - User Defined" to create a canvas that fits your needs. My figure is 15 by 10.5 cm and my canvas needed to be something like 17 by 12.5 cm.
3) Use b, t, l and r margins to move your figure on the canvas.
4) convert to pdf and take a look at the pdf if it matches your expectations.
I hope this is helpful for some people! It's probably quite a workaround but doesn't take so much time. Maybe it's not very helpful for automatisation...

gnuplot how to zoom y & y2 axis

I have a plot like this using wgnuplot:
the green and blue are on y2 axis.
Question 1:
When I zoom using right mouse button I get:
The black line on yaxis is to compressed near top. How can I get the y scale to fit the data for this window at this point AUTOMATICALLY. I.e.e without me having to type range commands?
Questions 2:
Again, is there anyway to rescale/zoom the y2axis ALONE, by mouse?
Just press 'a' or click the autoscale button to adjust the y-scale. Maybe you want to use set autoscale xfix before that.
Its not by mouse, but you can use the bind command to rescale only the y2-axis with the hotkeys 'alt-z' and 'alt-y':
bind 'alt-z' 'set y2range[GPVAL_Y2_MIN*2:GPVAL_Y2_MAX*2]; replot'
bind 'alt-y' 'set y2range[GPVAL_Y2_MIN*0.5:GPVAL_Y2_MAX*0.5]; replot'