Tag Info

Hot answers tagged

278

Mostly thanks to Belisarius's elegant wrapping, you can do h[fun_, divisor_, color_, at_] := Module[{k}, k = BSplineFunction[Table[fun@x + RandomReal[{-0.1, 0.1}/divisor], {x, 0.01, 10, .1}]]; ParametricPlot[k[x], {x,0.1,0.9}, PlotStyle->{color, AbsoluteThickness@at}, Axes-> None]]; Show[{ h[{#, 1.5 + 10 (Sin[#]^2/Sqrt[#]) Exp[-(# - 5)^2/2]} ...


247

The code below attempts to apply the XKCD style to a variety of plots and charts. The idea is to first apply cartoon-like styles to the graphics objects (thick lines, silly font etc), and then to apply a distortion using image processing. The final function is xkcdConvert which is simply applied to a standard plot or chart. The font style and size are set ...


62

Time to join in the fun. version 2 Result Method I produce the basic plot with ticks and labels: Plot[{x/2, (x + Sin[x])/2.2}, {x, 0, 2 Pi}, MaxRecursion -> 0, PlotPoints -> 30, Axes -> False, Frame -> {True, True, False, False}, FrameTicks -> {{{0.2, "Start", 0.07}, {3, "lunch", 0.05}, {6, "Finish", 0.06}}, None}, PlotLabel -> ...


60

In case you want more flexibility, it's also possible to design your own legends, for example along the lines of this MathGroup post. For your example, the process would start with the function legendMaker. Edited Instead of repeating the same definition as in the above post, I've overhauled legendMaker in response to image_doctor's answer, to separate ...


54

This can be done with Overlay if the ImagePadding and the horizontal range for each plot is the same. For example, plot1 = ListLinePlot[ Accumulate[RandomReal[{0, 1}, {100}]], PlotStyle -> Blue, ImagePadding -> 25, Frame -> {True, True, True, False}, FrameStyle -> {Automatic, Blue, Automatic, Automatic} ] plot2 = ...


54

I'm very late to the party, but here's a convenient xkcd guy generator: This was generated as: With[{ h = xkcdGuy[-10, "hat", 0.2, {20, -90}, {-57, -10}, {-20, 0}, {20, 0}], n = xkcdGuy[0, "none", -0.2, {-10, 0}, {50, 10}, {-20, 0}, {20, 0}]}, Graphics[{First@n, Rotate[Translate[First@h, {3.3, 0}], 10 Degree]}] ] // xkcdConvert using ...


52

To implement datenwolf's suggestion to perturb curves with Perlin noise to give that "hand-drawn" look and feel, here's one way to use one-dimensional Perlin noise for the perturbation: fBm = With[{permutations = Apply[Join, ConstantArray[RandomSample[Range[0, 255]], 2]]}, Compile[{{x, _Real}}, Module[{xf = Floor[x], xi, xa, u, i, j}, xi = ...


47

Since Mathematica does not have a built-in plot manipulating interface, here is a gui of a plot-manipulator. Updates are indicated with bold text. Functionality: Should work with any plot/graphics (ArrayPlot compatibility added); Drag anywhere in plot zooms in to selected rectangle; can be done repeatedly; Ctrl+drag zooms in/out (along vertical axis); ...


45

Building on Heike's ColorFunction, I came up with this: z = Transpose@Reverse@Sin@ Outer[Complex, Range[-Pi, Pi, 0.01], Range[-Pi, Pi, 0.01]]; hsbdata = Transpose[{ Rescale[Arg[z], {-Pi, Pi}], 1 - 0.05/Abs[Sin[2 Pi Abs[z]]], 0.02/Abs[Sin[2 Pi Abs[z]]] + Abs[Sin[2 Pi Im@z] Sin[2 Pi Re@z]]^0.25} , {3, 1, 2}]; Image[hsbdata, ColorSpace -> "HSB"] ...


34

Here's my solution, which constructs the three components and uses Inset to combine them into a single graphic. I've taken some care so that: the coordinate systems should line up across the plots (check the gridlines) as many graphics and plotting options are respected without breaking the layout the graphic can be reasonable resized ...


30

Needs["PolyhedronOperations`"] poly = Geodesate[PolyhedronData["Dodecahedron", "Faces"], 4]; amplitude = 0.15; twist = 4; verts = poly[[1]]; faces = poly[[2]]; phases = RandomReal[2 Pi, Length[verts]]; newverts[t_] := MapIndexed[{Sequence @@ (RotationMatrix[twist Last[#1]].Most[#1]), Last[#1]} (1 + amplitude Sin[t + phases[[First@#2]]]) &, ...


29

f[x_] := Tan[x] g[x_] := x sol = x /. NSolve[g[x] == f[x] && -10 < x < 10, x] Show[Plot[ {f[x], g[x]}, {x, -10, 10}], ListPlot[{#, g[#]} & /@ sol, PlotStyle -> PointSize[Large]]] Edit A little bit more sophisticated. Using the comments by @Oleksandr and @JM below. For the strange Exclusions specification I use below, see ...


29

Let me elaborate on @stevenvh's answer using Splines instead of Interpolation. The danger of using f'[0] is that the built-in interpolation requires that the (Hermite) polynomials go through each data points. Now if you data is noiseless that's fine, but if your data is noisy, the derivative of the interpolation will be all the more noisy (as a rule its ...


28

My friend C.P and I worked out these solutions. The 1st is C.P.s' Here we go. First things to know: 1) New Graph[] and related functionality in v8.0.4 is powerful in the sense that it does not only create an image but also stores all the information, including vertex coordinates, in that Graph[] object. 2) There is a GridGraph[...] function that makes ...


28

I take zero credit for this. It is a method I learned from Maxim Rytin. ContourPlot3D[{(x^2 + y^2 + z^2 + 8)^2 - 36 (x^2 + y^2), y^2 + (z - 2)^2 - 4}, {x, -4, 4}, {y, -4, 4}, {z, -2, 2}, Contours -> {0}, ContourStyle -> Opacity[0], Mesh -> None, BoundaryStyle -> {1 -> None, 2 -> None, {1, 2} -> {{Green, Tube[.03]}}}, Boxed -> ...


27

I'm posting this as a second answer, as it's really a completely different approach. It's also been substantially expanded as of April 25, 2012. While this still doesn't specifically address the question of adding a region, it does plot the countries separately. Of course, each country could be viewed as a region in itself. Our objective is to make a ...


27

Letting $j_k = i_{k+1}-i_k-1$ and writing $$Q(n) = P(n) - P(n-1) = C\sum_{0 \le j_1, j_2, \cdots, j_{51}\vert j_1+\cdots+j_{51}=n-52} \prod_{k=1}^{51}\left(\frac{k}{52}\right)^{j_k}\,,$$ with $C$ a constant, exhibits the $P(n)$ as cumulative sums of the $Q(n)$ and shows that $Q(n)$ is the coefficient of $x^{n-52}$ in the formal power series $$q(x) = ...


27

Disclaimer: I didn't actually look at the links in the comments because I wanted to see how well I could do on my own, so here's my original Mathematica cartogram creation! First, load the data from various web resources (as is done here): ClearAll["Global`*"] usa = Import[ "http://code.google.com/apis/kml/documentation/us_states.kml", "Data"]; ...


26

I second @Verbeia's suggestion: compute the function on a mesh of points and use ListContourPlot. The disadvantage is that ListContourPlot has no adaptive sampling, so it'd be preferable if we could do our own adaptive sampling somehow. Adaptive sampling can give you a much better result while needing to compute the function in far less points---and the ...


26

One possibility is to plot the contour plot with linear scales using ContourPlot and use ListLogLogPlot to transform this plot to one with logarithmic scales: pl = Normal@ ContourPlot[ Sin[3 x] + Cos[3 y] == 1/2, {x, .01 Pi, 3 Pi}, {y, .01 Pi, 3 Pi}, PlotPoints -> 30] ListLogLogPlot[Cases[pl, Line[a_, b___] :> a, Infinity], Joined -> ...


26

Just to be clear, the following is based on experimentation and could be wildly misleading... The outline of the algorithm for generating the mesh for Plot3D and DensityPlot appears to be: Create initial mesh based on the number of plot points Inject any user supplied points into the mesh Refine the mesh There are two issues to worry about when ...


25

Edit I updated the definitions of reportColorRange and colorLegend: added more comments in the code, allowed more customization options for the legend. Color gradients are produced by VertexColors for better-looking PDF export; gradients can also be replaced by color bands (using the "ColorSwathes" option). The labels on the color bar can be specified by ...


25

If what you want to visualize is how good the fit is, then you should do as @whuber suggests and plot the residuals, that is, the difference between the data and the fitted function. Below, each data point is drawn as a point with area proportional to the magnitude of the residual. Red means that the data value is higher than the fit; blue means the data is ...


24

After playing around for a while with various graphics and frame options... I decided to take the simplest option - your polygon one: Framed[Plot[Sin[x] Exp[x], {x, 1, 10}, Frame -> True, PlotRangePadding -> None, Axes -> False, Prolog -> {White, Rectangle[Scaled[{0, 0}], Scaled[{1, 1}]]}], Background -> LightGray]


24

In Mathematica 7 or 8, you can just use Tube. Please see the docs for many, many examples. Example: Show[ParametricPlot3D[{Cos[x], Sin[x], x/5}, {x, 0, 15}] /. Line -> (Tube[#, 0.2] &), PlotRange -> All]


23

How about this? bankerPlot[data_] := ListLinePlot[ data, AxesOrigin -> {0, 0}, Prolog -> Polygon[Join[data, Reverse[data.DiagonalMatrix[{1, 0}]]], VertexColors -> Join[ Blend[{Black, Blue}, #] & /@ Normalize[data[[All, 2]], Max], ConstantArray[Black, Length[data]] ] ], PlotStyle -> White, Background -> ...


23

Get a sample sound: snd = ExampleData[{"Sound", "SopranoSaxophone"}]; This gives us a Sound data structure with a SampledSoundList as first element. Extracting the data from it: sndData = snd[[1, 1, 1]]; sndSampleRate = snd[[1, 2]]; Plotting the data: ListPlot[sndData, DataRange -> {0, Length[sndData]/sndSampleRate }, ImageSize -> 600, Frame ...


23

You could plot the curve twice, with two different styles: Plot[{Sin[x], Sin[x]}, {x, 0, 2 Pi}, PlotStyle -> {Directive[Thickness[0.03], White], Black}] Changing the background to gray: Plot[{Sin[x], Sin[x]}, {x, 0, 2 Pi}, PlotStyle -> {Directive[Thickness[0.03], White], Black}, Background -> Gray]


23

You can also use MeshFunctions: Plot[{Cos[x], x Sin[x]}, {x, -3 Pi, 3 Pi}, MeshFunctions -> {(Cos[#] - # Sin[#]) &}, Mesh -> {{0}}, MeshStyle -> Directive[Red, PointSize[Large]]] Update: Dealing with Tan[x] using Exclusions Plot[{Tan[x], x Sin[x]}, {x, -3 Pi, 3 Pi}, MeshFunctions -> {(Tan[#] - # Sin[#]) &}, Mesh ...


22

Many posters already suggested good answers. I am just adding some explanation behind this behavior. Also, I have to warn that this is my understanding, and I couldn't find any reference. So, please take it with grain of salt. I am more than happy to stand corrected, if found wrong. Problem It is a rendering issue. And it is in fact Windows' GDI+ related ...



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