pgfplots width of plot - width

Consider the following example:
\documentclass{article}
\usepackage{tikz}
\usepackage{pgfplots}
\usepackage{subcaption}
\usepgfplotslibrary{patchplots}
\begin{document}
\begin{figure}
\begin{subfigure}{0.33\textwidth}
\centering
\begin{tikzpicture}
\pgfplotsset{%
width=\linewidth,
height=\linewidth
}
\begin{axis}[ticks=none,
xmin=0, xmax=1,
ymin=0, ymax=1,
axis x line=bottom,
axis y line=left,
]
\addplot[
patch,mesh,
patch type=quadratic spline,
style=very thick,
color=black]
coordinates {
(0,0) (0.9,0.9) (0.5,0.5^2)
};
\addplot[mark=none, color=gray] {x};
\end{axis}
\end{tikzpicture}
\end{subfigure}
\begin{subfigure}{0.33\textwidth}
\begin{tikzpicture}
\pgfplotsset{%
width=\linewidth,
height=\linewidth
}
\begin{axis}[ticks=none,
xmin=0, xmax=1,
ymin=0, ymax=1,
axis x line=bottom,
axis y line=left,
]
\addplot[
patch,mesh,
patch type=quadratic spline,
style=very thick,
color=black]
coordinates {
(0,0) (0.9,0.9) (0.5,0.5)
};
\addplot[mark=none, color=gray] {x};
\end{axis}
\end{tikzpicture}
\end{subfigure}
\begin{subfigure}{0.33\textwidth}
\begin{tikzpicture}
\pgfplotsset{%
width=\linewidth,
height=\linewidth
}
\begin{axis}[ticks=none,
xmin=0, xmax=1,
ymin=0, ymax=1,
axis x line=bottom,
axis y line=left,
]
\addplot[
patch,mesh,
patch type=quadratic spline,
style=very thick,
color=black]
coordinates {
(0,0) (0.9,0.9) (0.45,0.65)
};
\addplot[mark=none, color=gray] {x};
\end{axis}
\end{tikzpicture}
\end{subfigure}
\caption{Caption}
\label{fig:my_label}
\end{figure}
\end{document}
I would have expected my three plots to take up 1/3 of the page width each and be situated on a row next to each other. Instead I get this:
Not only are they smaller than expected but even though they are smaller they for some reason do not seem to fit on one line but are placed on two lines. What is going on hereā€½

Related

How do I rotate a point on the surface of a sphere given 3 degrees of rotation?

I have a point on a sphere that needs to be rotated. I have 3 different degrees of rotation (roll, pitch, yaw). Are there any formulas I could use to calculate where the point would end up after applying each rotation? For simplicity sake, the sphere can be centered on the origin if that helps.
I've tried looking at different ways of rotation, but nothing quite matches what I am looking for. If I needed to just rotate the sphere, I could do that, but I need to know the position of a point based on the rotation of the sphere.
Using Unity for an example, this is outside of unity in a separate project so using their library is not possible:
If the original point is at (1, 0, 0)
And the sphere then gets rotated by [45, 30, 15]:
What is the new (x, y, z) of the point?
If you have a given rotation as a Quaternion q, then you can rotate your point (Vector3) p like this:
Vector3 pRotated = q * p;
And if you have your rotation in Euler Angles then you can always convert it to a Quaternion like this (where x, y and z are the rotations in degrees around those axes):
Quaternion q = Quaternion.Euler(x,y,z);
Note that Unity's euler angles are defined so that first the object is rotated around the z axis, then around the x axis and finally around the y axis - and that these axes are all the in the space of the parent transform, if any (not the object's local axes, which will move with each rotation).
So I suppose that the z-axis would be roll, the x-axis would be pitch and the y axis would be yaw.You might have to switch the signs on some axes to match the expected result - for example, a positive x rotation will tilt the object downwards (assuming that the object's notion of forward is in its positive z direction and that up is in its positive y direction).

How to find the orientation of a plane?

I have three non-colinear 3D points, let's say pt1, pt2, pt3. I've computed the plane P using the sympy.Plane. How can I find the orientation of this plane(P) i.e. RPY(euler angles) or in quaternion?
I never used sympy, but you should be able to find a function to get the angle between 2 vectors (your normal vector and the world Y axis.)
theta = yaxis.angle_between(P.normal_vector)
then get the rotation axis, which is the normalized cross product of those same vectors.
axis = yaxis.cross(P.normal_vector).normal()
Then construct a quaternion from the axis and angle
q = Quaternion.from_axis_angle(axis, theta)

Traversing a grid of pixels inside projection plane

Suppose, I have a projection plane of length 2 like the below image:
If I divide the projection plane into a two dimensional
grid of screen_width x screen_height (720*480), then each pixel will be (2/720) distance apart in the x axis and (2/480) distance apart in the y axis and If I add x+(2/720) with my current co-ordinate, keeping the y constant I will move 1 pixel to the right side. Am I right?

Flot: How to keep x and y axes the same scale?

I want to plot on a standard Cartesian plane, so 1 unit on x axis has the same length as 1 unit on y axis. I also use the navigate plugin to zoom and pan. Is there anyway I can have this constraint? can't find anything about this in Flot api.
Thanks,
I had to do something similar and this was the first test: fiddle
The main point is that you set the max values for the axis in the same ratio as the width and height of your placeholder div:
options.xaxes[0].max = options.yaxes[0].max * $('#ph').width() / $('#ph').height();
$.plot($('#ph'), data, options);

How do I draw a set of vertical lines in gnuplot?

E.g. if I have a graph and want to add vertical lines at every 10 units along the X-axis.
From the Gnuplot documentation. To draw a vertical line from the bottom to the top of the graph at x=3, use:
set arrow from 3, graph 0 to 3, graph 1 nohead
Here is a snippet from my perl script to do this:
print OUTPUT "set arrow from $x1,$y1 to $x1,$y2 nohead lc rgb \'red\'\n";
As you might guess from above, it's actually drawn as a "headless" arrow.
alternatively you can also do this:
p '< echo "x y"' w impulse
x and y are the coordinates of the point to which you draw a vertical bar
You can use the grid feature for the second unused axis x2, which is the most natural way of drawing a set of regular spaced lines.
set grid x2tics
set x2tics 10 format "" scale 0
In general, the grid is drawn at the same position as the tics on the axis. In case the position of the lines does not correspond to the tics position, gnuplot provides an additional set of tics, called x2tics. format "" and scale 0 hides the x2tics so you only see the grid lines.
You can style the lines as usual with linewith, linecolor.
To elaborate on previous answers about the "every x units" part, here is what I came up with:
# Draw 5 vertical lines
n = 5
# ... evenly spaced between x0 and x1
x0 = 1.0
x1 = 2.0
dx = (x1-x0)/(n-1.0)
# ... each line going from y0 to y1
y0 = 0
y1 = 10
do for [i = 0:n-1] {
x = x0 + i*dx
set arrow from x,y0 to x,y1 nohead linecolor "blue" # add other styling options if needed
}

Resources