I am typing this in textedit and load it into gnuplot later. When I do so the image is slightly off the top of the screen which means I can't see some of it. Is there a way to shift the entirety of the imaged produced down, or start the z-axis lower on the image?
Also, how do I make either my points or my lines black? Currently the lines for my sphere are red and the points are blue.
set pointsize 2
set tics
set border
unset key
set size ratio -1
set size square
unset xzeroaxis
unset yzeroaxis
unset zzeroaxis
# linetype linewidth
set xrange[-1.2:1.2]
set yrange[-1.2:1.2]
set zrange[-1.2:1.2]
set view equal xyz
set xyplane at -1.2
set parametric
set isosamples 20
set hidden3d
set urange [0:2.0*pi]
set vrange [-pi/2:pi/2]
r=1.0;
# Parametric functions for the sphere
fx(v,u) = r*cos(v)*cos(u)
fy(v,u) = r*cos(v)*sin(u)
fz(v) = r*sin(v)
splot fx(v,u),fy(v,u),fz(v),"mypoints" u 1:2:3 w p 3
Thanks, A.
I shall try the transformation thing, but to try to explain my issue further just have a look at these pictures.
The first is what I get out when I run the code (now I have made everything black). The second is the same picture, but rotated (just by click, holding and moving the mouse around). As you can see on rotation the picture is off the screen. I just want the picture to be in the centre of the screen, I can't think why it wouldn't be.
Also why is there 1 or 1.5 of the z axis below the image? I don't really want that there either. Is there a way to set scales on x,y, and z axes equal? the set square thing has done it for x and y but as you can see the sphere is squished as well.
Thanks, A.
http://tinypic.com/view.php?pic=k59gx&s=6
http://tinypic.com/view.php?pic=2v9eo93&s=6
Note: I couldn't upload an image due to lack of rep, but I thought it would be the best way to illustrate my issue. The links show the images I am talking about.
Running your script, omitting the reference to "mypoints", I get the plot you want without any extra z-axis or the top getting cut off. I'm using gnuplot v.4.4.3. What version are you using? Have you tried it without also plotting "mypoints"? There might be something in there affecting the plot. Also, you might want to explore coordinate mapping (try "help mapping" at the prompt) to plot datafiles in spherical coordinates.
Ok, so basically there are loads of issues that need solving so here goes:
1) Don't shift the picture down, get rid of the little tag end from the z part of the border. This makes the picture more central.
To do this: set ticslevel 0.0
2) Aspect ratio is not maintained in X11 so it looks all squashed. This is spoken about here:
http://sourceforge.net/tracker/index.php?func=detail&aid=3331162&group_id=2055&atid=102055
The workaround as they say is to set the size of window that X11 outputs to to be square, to do this: set terminal x11 size 800,800
3) Note, you don't now need: set xyplane at -1.2 (or what ever z value you want) as this is taken care of using the set ticslevel command.
So now I have this:
set pointsize 2
set tics nomirror
set ticslevel 0.0
set border
set view equal xyz
unset key
unset xzeroaxis
unset yzeroaxis
unset zzeroaxis
# linetype linewidth
set xrange[-1.2:1.2]
set yrange[-1.2:1.2]
set zrange[-1.2:1.2]
set parametric
set isosamples 20
unset hidden3d
set urange [0:2.0*pi]
set vrange [-pi/2:pi/2]
r=1.0;
# Parametric functions for the sphere
fx(v,u) = r*cos(v)*cos(u)
fy(v,u) = r*cos(v)*sin(u)
fz(v) = r*sin(v)
splot fx(v,u) w lines lc rgb "black",fy(v,u) w lines lc rgb "black",fz(v) w lines lc rgb "black","mypoints" u 1:2:3 w points lc rgb "red" p 2
Hope this helps people in future.
Related
I'm trying to rotate 45ยบ a heat map coming from a matrix. The problem when rotating the discrete data is that the plot exceeds the window's size, reaching labels and tics place. Any idea or alternative to solve the problem?
Main code
set xrange[-20:20]
set yrange[30:50]
plot "test.txt" u ($2-$1+1):($2+$1):3 matrix with image notitle
And what I
obtain. The data file http://www.filedropper.com/test_146
I would suggest an alternative using splot with pm3d because the set pm3d has the option clip1in and clip4in which tells gnulpot which qudrangles to plot, but is available:
set pm3d map clip4in corners2col c1
set yrange[10:*]
splot 'test.txt' u ($2-$1+1):($2+$1):3 matrix with pm3d notitle
It will show some spurious triangles:
If you want to go for an interpolation, have a look at this question
Pay attention that splot [...] with pm3d will draw the colors of the quadrangles, so that if your matrix s NxM, you'll get (N-1)x(M-1). On the other hand using plot [...] with image you'll get NxM quandrangles. (see help image).
Using Gnuplot, I want to plot a PNG as a background image to a PDF file, which I later would like to plot curves onto. The aspect ratio of the axes should be 1, such that the image is not distorted. Furthermore, there should be no white borders around the image in the PDF file. Currently, I use:
set terminal pdf color solid
set output "input.pdf"
unset xtics
unset ytics
unset border
set size ratio -1
set lmargin 0
set rmargin 0
set tmargin 0
set bmargin 0
plot "input.png" binary filetype=png w rgbimage notitle
This leaves large white margins at the left and right borders.
When I omit set size ratio -1, there are no margins, but the image is distorted.
When I replace set terminal pdf color solid with set terminal pdf color solid size <width>, <height>, inserting the width and height of the PNG, I get the desired output, i.e. no margins and image retains its original aspect ratio. Unfortunately, in my workflow, this would require parsing and passing these values to Gnuplot automatically, which seems cumbersome.
Is there any reason why setting the margins to 0 does not work together with setting the aspect ratio to 1?
Do you have other solutions that do not require to pass the image dimensions to Gnuplot?
i am trying to plot a contour from a gridded data file called 'sample'. This script works fine for me:
set xrange[1:1e2]; set yrange[1:1e2]; set log;
set view map; unset surface
set style textbox opaque margins 0.5, 0.5 noborder
set contour base
set cntrlabel format '%5.3g' font ',7'
set cntrparam levels discrete 1e40,1e42,1e44
splot 'sample' u ($1*1e27):($2*1e18):3 wl
it plots a 2D plot with contour lines. All fine.
If i only dare to continue the plotting line with
'' u ($1*1e27):($2*1e18):3 with labels boxed notitle
to add labels to the contour lines, it takes around 15 minutes to produce a blank plot. Using gnuplot examples on sourceforge, it works.
Have you ever experienced something similar?
Many thanks in advance
Is there any way of labeling plots with images. For example, when I use the following:
plot(Y(:,1),Y(:,2),'o','LineWidth',2);
gname(names)
I can label each dot in a plot with a name. Is there any way to insert images instead of names?
It is possible, but not as convenient as gname by far. You can use the low-level version of image to insert images in your plot at arbitrary positions. Here's a simple example which puts the "Mandrill" image that comes with Matlab with its upper left corner pixel at the position (pi/2, 0):
% example plot
x = linspace(0, 2*pi, 100);
plot(x, cos(x))
% insert image
load mandrill
colormap(map)
image('CData', X, 'XData', [pi/2, pi/2 + 0.5], 'YData', [0, -0.3])
The result looks like this:
Problems with this approach:
There is no interactive point-and-click facility, you have to explicitly insert and position the image labels programmatically, or program such a point-and-click facility yourself. ginput might help doing so.
A figure window can only have one associated color map. That means if you have different images, they either all have to use the same colormap or have to be truecolor images.
Not just the position, but also the display size of the image has to be specified in the call to image, and both are by default specified with respect to the plot's coordinate system. This makes it hard to achieve the correct aspect ratio. You can switch (temporarily) to absolute units using the axes property 'Units' , but then you have to figure out the correct position in e.g. absolute millimeters or inches. Moreover, images are usually indexed with vertical coordinates increasing from top to bottom, while plots usually have vertical coordinates increasing from bottom to top. This is the reason for the negative value -0.3 in the 'YData' property above.
Alternatively, you can insert images each in their own little axes sitting on top of the plot's axes, which makes it easy to get the right orientation and aspect ratio using axis image. You'll still have the problem though to figure out the correct position for the axes.
Is it possible to display an image in multiple subplot axes, such that the image appears at the desired scale?
subplot(3,3,[1 4 7]);
%# image scaled down to fit 1 set of axes
imshow(img);
subplot(3,3,2);
plot(relevantData);
%# And so on with 5 other plots
I want to have the image scaled to either a fixed size or to fit the axes available to it, rather than to the size of a single axes.
My use case is to show a video alongside plots derived from the video, such that the plots are progressively drawn in step with the video. Once the display is correct I can save each image and combine them into a video.
Clarification
I am asking if it is possible to produce a figure as described without specifying the position of every element in absolute terms. Though one can make arbitrary figures that way (and in fact I have done so for this project), it is very tedious.
Edit:
For changing the size of the subplot:
In help subplot they mention that you can set parameters on the selected "axes" (that's what they call a plotting area in Matlab).
Using that, you can set the 'position', as seen in help axes. This property takes takes as argument:
[left, bottom, width, height]
As pointed out by #reve_etrange, one should use absolute positioning for axes 'Position'and 'OuterPosition' parameters. they can be in normalized coordinates, though.
For changing the size of the image in the subplot:
I think there are 2 useful things for you in the help imshow output:
'InitialMagnification': setting the magnification of the image.
'Parent': determines which parent imshow will use to put the image in (never tried using imshow with subplots).