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);
Related
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).
I have a set of 3d points (I generate the positions of planets and moons in a stellar system from Keplers equations) I have the coordinates of all points as x,y,z, where the central star is 0,0,0. The code to produce the points works perfectly.
However, at the moment I plot a visualisation of this system from above - so I just ignore the z component for the purposes of visualisation and plot the x and y to the canvas as-is. This works as intended.
How would I generate x and y coordinates for plotting to the canvas that take into account the z coordinate, so that I can plot a view from another angle apart from directly above?
The only library I can use apart from the standard one would be numpy. I cannot use Matplotlib.
edit thanks to the comments I can now clarify with some psudocode.
Assume I have a bunch of points that have an xyz position.
What I currently do:
canvas.plot(point.x)
canvas.plot(point.y)
ignoring point z - so that it is as if all z's are 0 and it is viewed from 'above'
So that I can use my current plotting code - which takes into account scale and offsets to do with the canvas, I need new x and y coordinates that are as if the view is from another angle other than 'above'.
It seems from the helpful comments what I have to do is rotate the whole coordinate system so that it has a new z axis that is a result of a rotation of the whole system about the x and y axis.
Something like the following psudocode would do.
def rotate_about_axis(x_rotation_degrees, y_rotation_degrees, point.x, point.y, point.z):
new_plot_x = canvas_point_to_plot after magic code to rotate coordinates x_rotation_degrees about x axis
new_plot_y = canvas_point_to_plot after magic code to rotate coordinates y_rotation_degrees about y axis
return new_plot_x, new_plot_y
Then I could apply this to all the points I plot.
How would I do this in python?
I have come up with an answer, I hope it helps someone.
import numpy, math
def rotate_about_axis(x_rotation_degrees, y_rotation_degrees, point_x, point_y, point_z):
xrads = math.radians(x_rotation_degrees)
yrads = math.radians(y_rotation_degrees)
rotation = [xrads, yrads, 0]
rotation_angle = numpy.linalg.norm(rotation)
norm_rotation = rotation / numpy.linalg.norm(rotation)
base_points = [point_x, point_y, point_z]
points = numpy.dot(base_points, norm_rotation) * norm_rotation
points_difference = base_points - points
points_transform = numpy.cross(norm_rotation, base_points)
rotated_points = points + points_difference * numpy.cos(rotation_angle) + points_transform * numpy.sin(rotation_angle)
rotated_point_x = rotated_points[0]
rotated_point_y = rotated_points[1]
return(rotated_point_x, rotated_point_y)
I'm making a bar chart in Matplotlib with a call like this:
xs.bar(bar_lefts, bar_heights, facecolor='black', edgecolor='black')
I get a barchart that looks like this:
What I'd like is one with no white gap between consecutive bars, e.g. more like this:
Is there a way to achieve this in Matplotlib using the bar() function?
Add width=1.0 as a keyword argument to bar(). E.g.
xs.bar(bar_lefts, bar_heights, width=1.0, facecolor='black', edgecolor='black').
This will fill the bars gaps vertically.
It has been 8 years since this question was asked, and the matplotlib API now has built-in ways to produce filled, gapless bars: pyplot.step() and pyplot.stairs() with the argument fill=True.
See the docs for a fuller comparison, but the primary difference is that step() defines the step positions with N x and N y values just like plot() would, while stairs() defines the step positions with N heights and N+1 edges, like what hist() returns. It is a subtle difference, and I think both tools can create the same outputs.
Just set the width 1 over the number of bars, so:
width = 1 / len(bar_lefts)
xs.bar(bar_lefts, bar_heights, width=width, color='black')
You can set the width equal to the distance between two bars:
width = bar_lefts[-1] - bar_lefts[-2]
xs.bar(bar_lefts, bar_heights, width=width)
I am trying various visualizations for an Igraph in R (version.3.3.1).
Currently my visualizing is as shown as below, 2 nodes (blue and green) in circular layout.
Circular Layout
visNetwork(data$nodes,data$edges) %>% visIgraphLayout(layout="layout_in_circle")
Now I want to have a semicircle structure instead of a full circle as in the pic. All blue nodes form a semicircle, green nodes another semicircle. Each semicircle separated by a small distance as well. How can i achieve this. I found grid package has an option for semicircle, but i couldnt make it work with igraph. Please provide some pointers.
The layout argument accepts an arbitrary matrix with two columns and N rows if your graph has N vertices; all you need to do is to create a list of coordinates that correspond to a semicircle. You can make use of the fact that a vertex at angle alpha around a circle with radius r centered at (0, 0) is to be found at (r * cos(alpha), r * sin(alpha)). Since you are using R, alpha should be specified in radians, spaced evenly between 0 and pi (which corresponds to 180 degrees).
I have a weird issue in my bar graph realized using d3.js: the 1 px padding between each rectangle appears irregular. I gather either or both the width or x position are the culprit but i don't understand what i'm doing wrong: the width is a fraction of the svg area and the X position is obtained via a D3 scale.
I've put a demo here: http://jsfiddle.net/pixeline/j679N/4/
The code ( a scale) controling the x position:
var xScale = d3.time.scale().domain([minDate, maxDate]).rangeRound([padding, w - padding]);
The code controlling the width:
var barWidth = Math.floor((w/dataset.length))-barPadding;
Thank you for your insight.
It's irregular because you are rounding your output range (rangeRound). In some cases, the distance between two bars is 3 pixels and sometimes only 2. This is because the actual x position is a fractional value and ends up being rounded one way in some cases and the other way on other cases.
You can mitigate the effect but changing rangeRound to range, but that won't eliminate it entirely as you'll still get fractional pixel values for positions. The best thing to do is probably to simply increase the padding so that the differences aren't as obvious.