Hot answers tagged

22

Normally Plot uses machine precision numbers; your $x^x$ expression is hitting the limit of the numbers that can be represented in machine precision right about $x>143$. Note: Solve[$MaxMachineNumber == x^x, x] (* Out: {{x -> 143.016}} *) You can increase the WorkingPrecision setting for Plot adequately, and the plot will be complete: f[x_] = ...


13

I don't think there is a special ribbon function. But you can plot one pretty easily. Here's an example. The functions x[u] and y[u] define a curve in space and then z[s] gives it width. x[u_] := Sin[u] u^2 y[u_] := 2 Cos[u] + u^2 z[s_] := s ParametricPlot3D[{x[u], y[u], z[s]}, {u, 0, 6}, {s, -2, 2}, Boxed -> False, Axes -> False] Here's ...


9

I don't know how to do this in an automated way, but here is something at least: Make your plot, extract the lines, convert them to regions, and then take the RegionDifference between them plot = ContourPlot[x*Exp[-x^2 - y^2], {x, 0, 3}, {y, -3, 3}, PlotRange -> {0, 0.5}, ColorFunction -> "Rainbow"] points = Cases[Normal@plot, Line[pts__] -> ...


8

If you have a relatively recent version of Mathematica, you don't need to use Evaluate. X = {Unique["x"]}; With[{x = X[[1]]}, Plot[Legended[2 x, x], {x, 0, 1}]]


7

To answer the last question, the contour domains (since V8) are enclosed separately in GraphicsGroup, each which you can cull and turn into a region: plot = ContourPlot[x*Exp[-x^2 - y^2], {x, 0, 3}, {y, -3, 3}, PlotRange -> {0, 0.5}, ColorFunction -> "Rainbow"]; regs = With[{coords = First@Cases[plot, GraphicsComplex[p_, ___] :> p, Infinity]}, ...


7

You ask whether it is "possible to define the areas with the same color as separate geometric regions in the sense of the computation geometry, and then work with these domains separately". This seems to me to be a great task for ImplicitRegion: regions = Table[ ImplicitRegion[i < x*Exp[-x^2 - y^2] <= i + 0.05, {{x, 0, 3}, {y, -3, 3}}], {i, 0, 0.4, ...


6

TL;DR - Evaluate the function for just one value before trying to plot it. This will always save you hassle and headaches. And if your function involves a summation out to infinity, make sure it converges. Use atomic units when working on atomic-scale problems. I personally stay away from the Units functionality altogether, and just enter the numbers in ...


6

In the absence of your data, I'll just use some data that I make up. One of these is an example from the help on ListContourPlot3D and one is a 3D-Gaussian, list1 = Table[{x, y, z, x^2 + y^2 - z^2}, {x, -1, 1, .05}, {y, -1, 1, .05}, {z, -1, 1, .05}]~Flatten~2; list2 = Table[{x, y, z, 2 Exp[-3^2 ((x - .3)^2 + (y - .3)^2 + (z - .3)^2)]}, {x, -1, ...


6

This approach splits each data set in to a set of curves and then attempts to join curves whose end and start points are "close enough". The measure I have used is okay for the example data and it includes an element of rescaling with the curve data but YMMV with "real" data. It is simpler than some of the linked approaches. Firstly we use a helper ...


5

Always avoid using subscripts, they just confuse things. Instead of defining Subscript[t,0]=0, define t[0]=0. Finally, Do loops are easier to read and write than For loops, which generally come from other programming languages. Does this do what you were going for? t[0] = 0; x[0] = 1; h = 0.2; Do[ t[n + 1] = t[n] + h; x[n + 1] = x[n] + (t[n + 1] - ...


5

To produce the behavior you want, you should make your function Listable: Clear[normalListable] normalListable[a_, t_] := {Sin[a], 2 Cos[a]} + t*{-2 Sin[a], -Cos[a]} SetAttributes[normalListable, Listable] Your function will now be automatically threaded over any lists in its input. Notice the difference: normal[{2, 3}, t] (* Out: {{Sin[2] - 2 t Sin[2], ...


5

f1[y_] := f[Mod[y, 4]] Plot[f1[x], {x, -8, 8}]


5

We can use the following approach: start with an end point that belongs to a path and increment the path with nearest neighbor points that are "good candidates." A point is a "good candidate" if it is not too far away from the last point and it does not produce a sharp turn in the path. To determine "too far" we a look at the distances between the last, say, ...


5

As David G. Stork has pointed out, Nearest Neighbours offer a good method of attack for this problem. Here I've not implemented a full NN chain approach but something a little more basic which gets most of the way there. I'm using a 'dumb' NN but with a distance function that only allows points to be connected to another point one x-distance away, this ...


4

I'm not sure if it's a bug but it very may well be. This doesn't happen when you use other Wrapper objects, like Tooltip or PopupWindow.But what seems to be going on is that it wants to give the same plot marker and style to each sublist. One way to get your colors back is to use ListPlot[Transpose@{Table[{Cos[t], Sin[2 t]}, {t, 0, 2 Pi, Pi/20}]}, ...


4

I would suggest separating the substance of your computation from the labels/formats. I also suggest searching this site on reasons for avoiding for loops. For example, fun[n_, h_] := NestList[{#[[1]] + h, #[[2]] + h (#[[2]] + #[[1]]^2)} &, {0, 1}, n] codes your function (barring any error on my part). Then, TableForm[fun[5,0.2], TableHeadings ...


4

Your x-axis values are on a log scale, so you need to use Log values for the gridlines. Show[%, errorplot1, AxesStyle -> {Opacity[0], AbsoluteThickness[3]}, Frame -> True, GridLines -> {Log@{100, 150, 200, 250, 300, 350}, {-6, -5, -4, -3, -2, -1}}, GridLinesStyle -> LightGray] Edit This is if you want to add the gridlines ...


4

A simple way could be using the PlotRange. Table[ ContourPlot[x*Exp[-x^2 - y^2], {x, 0, 2}, {y, -1, 1}, PlotRange -> {i, j}, ColorFunction -> "Rainbow", PlotLegends -> True, PlotLabel -> {i, j}] , {i, 0.1, 0.3, 0.1}, {j, i + 0.1, 0.4, 0.1}] // TableForm For a line, simply put the value ContourPlot[x*Exp[-x^2 - y^2] == 0.3, {x, ...


4

When you evaluate the statement opt=="def" it evaluates to True if opt really is "def", but it doesn't give False for any other object. Read the answer here to see why you need to use SameQ (===) instead of Equal (==), f[a_, opt_] := Module[{defOpt, opt2}, defOpt = {PlotLabel -> "Label"}; If[opt === "def", opt2 = defOpt, opt2 = Join[defOpt, opt]]; ...


4

p = ContourPlot[x*Exp[-x^2 - y^2], {x, 0, 3}, {y, -3, 3}, PlotRange -> {0, 0.5}, ColorFunction -> "Rainbow"]; colors = Cases[p, _RGBColor, -1]; poly = Cases[Cases[Normal@p, {__, colors[[2]], __}, -1],Polygon[__], -1]; r = RegionUnion[poly]; lines = Cases[Normal@RegionPlot[r], Line[__], -1]; Graphics[lines]


4

I first thought this was a bug, but then I recalled the fact that grid dividers can be specified by part. This worked in this case too. RegionPlot[{Disk[], Disk[{1, 0}]}, BoundaryStyle -> { 1 -> Directive[Orange, Thick], 2 -> Directive[Black, Thick]}]


4

It's because the different elements of your PlotMarkers option refer to different data sets, whereas you just have the one data set. If you were only after different coloured data points then you could Style each element of your data set, however I don't know if its possible to do this with different symbols. A kind of hacky solution is just to convert ...


3

DateHistogram was added in version 10.2, and uses date-specific bins and ticks. I'll use the same {month, day} data as my other example, but instead of transforming the dates ahead of time, I can use DateFunction to provide the interpretation automatically. blossom = {{4, 3}, {4, 22}, {4, 15}, {4, 2}, {4, 18}, {4, 20}, {4, 12}, {3, 30}, {4, 4}, {4, ...


3

To define a function with options, give it a set of defaults and use OptionsPattern in the definition. To use the value of a particular option in the function defintion, use OptionValue: Options[f] = {"ThisIsAnOption" -> False, SoIsThis -> 1}; f[a_, opt : OptionsPattern[]] := (If[OptionValue["ThisIsAnOption"], Print[{opt}]]; a + ...


3

A compact approach is ParametricPlot[ReIm[Log[θ] Exp[I θ]], {θ, 0, 2 Pi}] producing the same curve that appears in the answer by thedude. It works for any complex function of a single real variable. Appropriate to the season, a cartiod can be plotted by ParametricPlot[ReIm[I(Exp[I θ] + 1)^2], {θ, -Pi, Pi}]


3

I solved it by adding the grid lines to the theoretical function. Still curious why it didn't work the way I did it in my question though. Edit: Here's my code that solved it. Needs["ErrorBarPlots`"] Needs["ErrorBarLogPlots`"] errorplot1 = ErrorListLogLinearPlot[{{{100.15, -5.3}, ErrorBar[0.4]}, {{150.05, -3.0}, ErrorBar[0.4]}, {{200.32, -2.2}, ...


3

How can I just directly assign positions? You can do it manually by creating Graphics3D text objects and positioning them alongside the plot. You can specify their coordinates using Scaled coordinates, Show[ Plot3D[Evaluate[ p[r/100, c, n, 1]^-1*D[p[r/100, c, n, 1], r] /. r -> 6], {n, 1, 20}, {c, 0, 0.1}], Graphics3D[Text["years", ...


3

I post this just to illustrate another way using FrenetSerretSystem which would be useful for plotting the evolute, e.g. pt[u_] := Module[{t, fs}, fs = FrenetSerretSystem[ellipse[t], t]; {ellipse[u], ellipse[u] + (fs[[2, 2]]/fs[[1, 1]]) /. t -> u}] Visualizing: list = With[{res = pt /@ Range[0, 2 Pi, 0.1], p1 = ParametricPlot[ellipse[t], {t, ...


3

You can use LabelStyle -> Directive[Bold, Red] and LabelStyle -> Directive[Bold, Blue] Manipulate[ If[reflection, Plot[{-func}, {x, -3, 3}, PlotStyle -> Red, PlotRange -> {{-3, 3}, {-3, 3}}, GridLines -> Automatic, PlotLabel -> StringForm["f(x) = ``", -func], LabelStyle -> Directive[Bold, Red]], Plot[{func}, {x, -3, ...


3

Example plot: Plot[{Cos[x], Sin[x], Tan[x]}, {x, 0, 2 π}] Now, just copy this plot from the notebook (using ctrl-C) and paste it in the front of following expression: /. a : RGBColor[__] :> ColorConvert[a, "Grayscale"] The result:



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