In numpy, it is possible to visualize an array of numeric values by using imshow. I wish to produce similar images in Haskell, including displaying axes, titles, and so on. Additionally, it would be useful if it were possible to overlay e.g. geometric shapes on top of the visualized array.
I see many libraries that might already implement this kind of functionality, but can't find it myself. If it does not exist, where would be my best bet to start ?
The answers to this SO question contain some suggestions and code examples:
Which haskell library will let me save a 2D array/vector to a png/jpg/gif… file?
imshow doesn't come from numpy, it comes from matplotlib. matplotlib is a native Python library, so to use it in a Haskell program you'd need to get to it through the Python c API. There's already a library of Haskell bindings to the Python c API, cpython. This would probably be a bit tricky to use because it can't marshall functions, and, although I'm not familiar with matplotlib, plotting libraries typically take functions for features such as tick and label formatting.
From the plot package
ms :: Matrix Double
ms = buildMatrix 64 64 (\(x,y) -> sin (2*2*pi*(fromIntegral x)/64) * cos (5*2*pi (fromIntegral y)/64))
mat_fig = do
setPlots 1 1
withPlot (1,1) $ do
setDataset ms
addAxis XAxis (Side Lower) $ setTickLabelFormat "%.0f"
addAxis YAxis (Side Lower) $ setTickLabelFormat "%.0f"
setRangeFromData XAxis Lower Linear
setRangeFromData YAxis Lower Linear
You can also add title and subtitle and you can use annotations to draw arbitrary shapes on the plot area.
Related
I have a 3d spherical point set of 10 points, (2 layers of pentagonal loudspeaker array) 2. I want to obtain 2D representation of this configuration. (Mollweide, Mercator, Cylindirical or Equirectangular projection?)
I will set the axis so that they give corresponding elevation and azimuthal angles. An example is given in 1 (Taken by ALLRADecoder vst plugin by IEM)
Is there a way to do this with a Python package like matplotlib, mayavi, or similar?
If you want to actually render something similar to above, you might want to look at PyOpenGL however it might not be the most intuitive package to dive into.
If you want to just get the 2d set of points this 3d object makes you could just look at doing some projection maths and then a package like pygame would be ideal for plotting this 2d representation and is quite user-friendly if you're new to python and graphics.
I have installed Point Cloud Library(PCL) package for using Iterative closest point (icp) my question is: this package could be used for 2D data or not ?I want to align two TSNE data which are 2D.Link of the icp method
It is not a problem even if it supported only 3D. You can add a z=0 coordinate to your data points and the z component will always be zero in your solution.
PCL does not have a paired data ICP to the best of my knowledge, but it should be pretty trivial to write as the cost function just considers squared distance between each pair.
I would create clouds of the two sets of points, setting z to zero, write your cost function (sum of squared distances of each pair), and then cycle the icp through xy translation steps and z rotation steps using reverse half-ing style icp stepping.
I am calculating an dynamic resistance of a diode and I have a lot of measurements and I've created a graph from them. And the question is, how do I find from this graph an exact value of arguments, for example: I want to obtain f(x) value for x=5 where i have measurement for exact value fe. x=10 -> y=213, x=1 y->110, and got a graph curve, but how to find f(5) = ?
This is not trivial: it will depend on your interpolation scheme and Excel does not expose the scheme it uses when drawing a graph.
Unless you tell it otherwise, Excel (I think) uses a Bezier Curve with 2 control points to perform its graphing.
This interpolation scheme transforms, via some linear algebra, to a cubic spline interpolation.
But to use cubic spline interpolation, you need more than two data points.
Since you've only given us two points, the best thing you can do is to interpolate linearly but that will not be what Excel does.
An answer more detailed than this if anything will epitomise the rather broad nature of your question. Do Google any terms that I've used: armed with a bit of time and a good internet connection, you ought to be able to solve this problem adequately.
See https://en.wikipedia.org/wiki/Spline_interpolation, https://en.wikipedia.org/wiki/B%C3%A9zier_curve
I think that you can use a preinstalled add-on named Solver. You have to activate it as shown here.
Then you have to follow one of the tutorial you can find over the Internet (like this one) without finding min o max but finding the exact value you want.
I want to draw a section graph for XYZ CIE color model, like this one:
Do you have any idea how to do it?
Very briefly...
You can plot the spectral line (the horseshoe) by plotting the xy (I have XY not xy) data for the standard observer. Then you can find the polygon you need to fill by applying a convex hull algorithm to the points. Make a list of xy values you want to paint within the polygon. Find the z value for a fixed luminance by z = 1 - x - y. Convert to RGB - you will need a function called something like XYZtoRGB (there is a python module, or use the transform on wikipedia). You may want to increase the luminance by multiplying all the numbers by a constant or something first. Set the pixels at the xy locations to the RGB values. Plot along with the convex hull and/or the spectral line you calculated.
I have the data for the standard 2deg (I think) observer (I can't find a link) - you will need to divide by X+Y+Z to convert from XYZ to xyz. Send me a message if you want me to send them to you, there is too much data to post here.
The colour Python module has a plotting submodule where this kind of plot is one of the provided plots. See documentation for plot_chromaticity_diagram_CIE1931 and plot_sds_in_chromaticity_diagram_CIE1931
It uses Matplotlib under the hood.
Given two 3D vectors A and B, I need to derive a rotation matrix which rotates from A to B.
This is what I came up with:
Derive cosine from acos(A . B)
Derive sine from asin(|A x B| / (|A| * |B|))
Use A x B as axis of rotation
Use matrix given near the bottom of this page (axis angle)
This works fine except for rotations of 0° (which I ignore) and 180° (which I treat as a special case). Is there a more graceful way to do this using the Direct3D library? I am looking for a Direct3D specific answer.
Edit: Removed acos and asin (see Hugh Allen's post)
No, you're pretty much doing it the best way possible. I don't think there is a built-in DirectX function that does what you want. For step 4, you can use D3DXMatrixRotationAxis(). Just be careful about the edge cases, such as when |A| or |B| is zero, or when the angle is 0° or 180°.
It's probably more of a typo than a thinko, but acos(A.B) is the angle, not its cosine. Similarly for point 2.
You can calculate the sin from the cos using sin^2 + cos^2 = 1. That is, sin = sqrt(1-cos*cos). This would be cheaper than the vector expression you are using, and also eliminate the special cases for 0/180 degrees.
You might look at the following article from siggraph link text
Maybe you can use D3DXMatrixLookAtLH ?