Tag Info

Hot answers tagged

67

TL;DR: A package (Mathematica v10) can be found at the very bottom of this post. UPDATES 6: Tiny update: Import can now use the ".bvh" extension to determine the import type. The code that does this is ugly, but I don't see any other way at the moment. out = Import["C:\\Female1_C03_Run.bvh"] 5: Added error checking and registered the package ...


54

A major point behind the video is that Mobius transformations are simplest when viewed on the sphere. Thus, we'll never actually define a Mobius transformation - we'll do that part on the sphere. Of course, we will need to project back and forth. Here are the stereo graphic projection and it's inverse implemented as compiled functions for speed. This is ...


41

Here's a way to morph the boundaries. After finding the boundaries by Thinning of the result of EdgeDetect, FindCurvePath finds a sequence of points that traces a path around each segment. MorphologicalComponents numbers the component left to right, top to bottom, so that 1 is the apple leaf, 2 is the i-dot, 3 is the apple body, and 4 is the i-stem (5, 6 ...


34

Let you have a function and an initial point f[x_] := Cos[x] x0 = 0.2; Then you can calculate a sequence seq = NestList[f, x0, 10] (* {0.2, 0.980067, 0.556967, 0.848862, 0.660838, 0.789478, \ 0.704216, 0.76212, 0.723374, 0.749577, 0.731977} *) and vizualize it with a so-called Cobweb plot p = Join @@ ({{#, #}, {##}} & @@@ Partition[seq, 2, 1]); ...


29

I've taken the liberty of uploading the RGB values for MyCarta's color schemes to pastebin. Mr. Niccoli provides these in CSV downloadable from his website, but I found that I had to change their format if I want Mathematica to read them during initialization. Download the RGB color values for the cube 1, cubeYF, and LinearL from pastebin and put them into ...


25

Some function definitions first. AkimaInterpolation[] stolen from here (Thanks JM, wherever you are!): AkimaInterpolation[data_] := Module[{dy}, dy = #2/#1 & @@@ Differences[data]; Interpolation[Transpose[{List /@ data[[All, 1]], data[[All, -1]], With[{wp = Abs[#4 - #3], wm = Abs[#2 - #1]}, If[wp + wm == 0, (#2 + #3)/2, (wp #2 + wm ...


24

One way to do it would be to use glyphs. We can extract the curves that make up the two characters as follows: a = First@First@Last@First@First@ ImportString[ExportString[ Style[FromCharacterCode[61440], 24, FontFamily -> "Baskerville Old Face"], "PDF"], "PDF", "TextMode" -> "Outlines"]; b = First@First@Last@First@First@ ...


23

Since you want the animation to have explanatory content, I thought it might be best to incorporate the explanatory 2D diagram into the 3D scene. So I imagine the 2D plot as a "sticker" that can be put onto the cylinder, like a label on a bottle. That way, you can see the explanatory diagram itself wrap around the cylinder and become identical to the ...


20

Graphics[{Circle[{0, 0}, 1, {0, Pi}], Circle[{0, 0}, .03], Line[{{1, 0}, {1, -.1}, {-1, -.1}, {-1, 0}}], Rotate[ Line[{{.03, 0}, {.6, 0}}] , #, {0, 0}] & /@ {0, Pi/2, Pi}, GeometricTransformation[ Piecewise[{ {{Red, Line[{{.8, 0}, {1, 0}}], Black, Line[{{.2, 0}, {.5, 0}}], Rotate[{Red, Text[#, {.75, 0}, {0, ...


19

Method 1: FindCurvePath (as mentioned by Yves Klett). This method is simple, but unfortunately, there are small issues (as shown in plots), that the curves are not identified perfectly. arrayData = Flatten[Function[{lst}, {First @ lst, #} & /@ Rest[lst]] /@ originalData, 1]; curvesPosition = FindCurvePath[arrayData]; ListPlot[curves = ...


18

Let us do it purely by image-processing. The main idea is to use DistanceTransform here. {img1, img2} = ImageResize[#, Scaled[3]] & /@ Import /@ {"http://i.stack.imgur.com/RKHo5.png", "http://i.stack.imgur.com/MFGR4.png"} The signed distances to the boundaries of all morphological components are dist = ...


16

Update According to KennyColnago's advice, post-processing is not needed, as StreamColorFunction can handle it essentially by using VertexColors on Line-s: ListStreamPlot[ testdata, StreamPoints -> {samplePoints, Automatic, 10}, StreamStyle -> "Line", Background -> Black, ...


13

Here's my attempt at recreating the LinearLCM palette. It turned out to be very tricky, because it's not a linear problem. In addition the blog article and the paper cited are confusing the terms "luminance" and "lightness". I started the process with trying to recreate the uniform-luminance rainbow palette on the left: ...


13

You have to create your own mesh and you have to convert your u and v to mesh interpolations. (In the example in the documentation, NDSolveValue does this itself in constructing uif, vif.) Example: Needs["NDSolve`FEM`"] mesh = ToElementMesh[FullRegion[2], {{0, 5}, {0, 1}}]; u = Function[{x, y}, x (y - 0.5)/25]; v = Function[{x, y}, -x^2/50]; uif = ...


13

I have to admit, that I only copied your code and tried it without actually reading what you have done, but I guess I can help to fix at least the second image. What you are after is the "DepthPeelingLayers" settings that you can access with the option inspector: When you raise this number to e.g. 32, the output looks like this This can also be done ...


11

This seems to work pretty well: r = 0.2/3; regions = RegionPlot[ Evaluate@Table[ Length@clique PDF[SmoothKernelDistribution[data[[clique]], r], {x, y}] > 1/(4 π r^2), {clique, mycliques}], {x, -2 r, 1 + 2 r}, {y, -2 r, 1 + 2 r}, Frame -> False]; Show[regions, Graph[mygraph, GraphStyle -> "BasicBlack"]] Further reading: ...


11

ListPlot[] isn't the "right" tool. It can be done with Epilog ->, but it's more natural to use Graphics[] and Nearest[]: (* Generate a distribution similar to your example *) n = 1000; rs = RandomVariate[TransformedDistribution[Sqrt@x,x\[Distributed] UniformDistribution[{.1, 1}]], n]; phis = RandomReal[{0, 2 Pi}, n]; pts = #1 {Cos@#2, Sin@#2} & @@@ ...


11

One can use the periodicity over $\theta$ and add one periodic copy of the data. In this case FindCurvePath works much better. I also add an interpolation of the result arrayData = Flatten[Thread@{#, Join[{##2}, {##2} + 2 π]} & @@@ originalData, 1]; curvesPosition = FindCurvePath@arrayData; {t, θ} = Interpolation@Transpose@{Range[0., 1, 1/(Length@# - ...


10

As suggested by Sektor I am adding this as a separate answer. DumpsterDoofus' asked in a comment about perceptual, divergent colour schemes (where "zero is special"). I am about to publish a tutorial with a number of them. The tutorial will be in the form of a IPython notebook, but I will also share the palettes as ASCII files. I am definitely not a ...


9

gr = Normal@StreamPlot[{Cot[θ] Cos[ϕ], -Sin[ϕ]}, {ϕ, -π, π}, {θ, 0, π}, StreamColorFunction -> Hue]; Graphics3D[Cases[gr, _Arrow, Infinity] /. {x_Real, y_Real} :> {Cos[x] Sin[y], Sin[y] Sin[x], Cos[y]}]


9

There exists a simple trick for your purpose, here is my implementation: f[a][b][c][d] //. g_[x_][y__] :> g[x, y] /; (Print[g[x][y] -> g[x, y]]; True) Log[Sqrt[a (b c^d)^e]] //. {Log[x_ y_] :> Log[x] + Log[y] /; (Print[Log[x y] -> Log[x] + Log[y]]; True), Log[x_^k_] :> k Log[x] /; (Print[Log[x^k] -> k Log[x]]; True)} Not as ...


8

dottie = FindRoot[Cos[x] == x, {x, 1}] // Values // First 0.739085 Plot[{Cos[x], x}, {x, -5, 5}, Epilog -> {Red, PointSize[0.02], Point[{dottie, dottie}]}] Convergence can be seen with EvaluationMonitor {res, {evx}} = Reap[FindRoot[Cos[x] == x, {x, 0}, EvaluationMonitor :> Sow[x]]] {{x -> 0.739085}, {{0., 1., 0.750364, 0.739113, ...


8

You can post-process the graphics output to shift the arrows: vp1 = VectorPlot[{-1 - x^2 + y, 1 + x - y^2}, {x, -2, 2}, {y, -2, 2}, VectorPoints -> points, VectorScale -> {.5, .4}, ImageSize -> 400, Prolog -> {Yellow, Opacity[.5], Rectangle[{-1, -1}, {1, 1}], Opacity[1], Red, PointSize[Large], Point[points]}]; vp1b = vp1 ...


7

Until someone comes up with a less convoluted approach, you can post-process the output of BoxWhiskerChart to color and/or to downsample the outliers as follows: data = Flatten[{RandomReal[1., 10000], RandomReal[2., 2000]}]; b1 = BoxWhiskerChart[data, {"Median", {"MedianMarker", 1, Black}, {"Whiskers", Black}, {"Fences", 0.5, Black}, ...


7

Both, DistributionChart and SmoothHistogram are models using a "smooth kernel density estimate". Consider the simplest case with two points only: DistributionChart[{0, 1}, GridLines -> Automatic] SmoothHistogram[{0, 1}, GridLines -> Automatic] For your data we get dat = Flatten[{RandomReal[1., 10000], RandomReal[2., 2000]}]; ...


7

I tried to use the above mentioned codes for plotting error ellipses for 2D-Data. However, I did not get the anticipated results, because an error occured when Mathematica tried to solve the equality in the function Counterplot for my data. I found another solution based on the explicit calculation of the ellipse by means of covariance analysis. The ellipse ...


7

An alternative way to post-process the StreamPlot output into a Graphics3D object using @user18792's trick: sp = StreamPlot[{Cot[θ] Cos[ϕ], -Sin[ϕ]}, {ϕ, -π, π}, {θ, 0, π}, StreamColorFunction -> Hue, ImageSize -> 400]; sp3d = Graphics3D[sp[[1]] /. Arrow[z_] :> Arrow[z /. {x_Real, y_Real} :> {Cos[x] Sin[y], Sin[y] Sin[x], Cos[y]}], ...


7

It looks like you want to plot the phase-only information of a complex function. Using the following helper functions for plotting the phase-only information complex functions: hue = Compile[{{z, _Complex}}, {Mod[3 π/2 + Arg[z], 2 π]/(2 π), 1, If[Abs[z] > 10^-3, 1, 0]}, CompilationTarget -> "C", RuntimeAttributes -> {Listable}]; ...


7

This is not a protractor, but it is a related application that that serves as an example of rotated text which is the only thing missing in the protractor shown in the question. I did it a while a go and keep it near the kitchen oven: c[f_]:=5/9 (-32+f) f[c_]:=1/5 (160+9 c) cToAngle[c_]:=(c+40)/300*(2\[Pi]-5Degree) ...


6

I'm sure there are lots of things one might try -- here is an attempt using some of the built in options that are available in ListStreamPlot: Show[Graphics[{Black, CountryData["USA", "Polygon"]}], ListStreamPlot[ Table[{{x, y}, Through[{Cos, Sin}[ WeatherData[{y, x}, "WindDirection"]]]}, {x, -140, -70, 5}, {y, 24, 50, 5}], StreamScale ...



Only top voted, non community-wiki answers of a minimum length are eligible