Hot answers tagged

23

Source of the problem (possibly) Here is a clear indication that your Fortran library and the Mathematica function are behaving in fundamentally different ways. I noticed the apparent high frequency oscillations in the difference functional, so I decided to see exactly how quickly they oscillate, Plot[funcfortran[w, 0.06, -1.0, 1.0, 1.0, N[π/2], 2.0, 3., ...


21

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_] = ...


12

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 ...


8

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

Try this ContourPlot[Cos[x - y] + Sin[x^2 + 3 y], {x, -3, 3}, {y, -3, 3}, PlotTheme -> "Monochrome",ContourStyle -> Directive[White, Opacity@.1]] You can also use ColorFunction -> ColorData["GrayTones"] for gray shades or even write your own following the reference.


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

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]}, ...


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

I share the sentiment that this question should have shown a lot more effort. Nonetheless, plot styling is quite possibly the most maddening and least intuitive aspect of Mathematica, at least in my opinion. The sheer quantity of options is daunting. With that in mind, here is a way to achieve something similar to what the OP requested, to get started. ...


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

You can use a custom Piecewise function for the plotting, Plot[Evaluate[ Table[Piecewise[{{y[b][x], x <= b}}, Null] /. sol, {b, {0.3, 0.2, 0.1}}]], {x, 0, 0.3}]


4

Here is a partial solution. Partial, because it seems to me that the mesh and the solution do not match. The mphtxt file is a structured representation of a mesh. This file is made up of several sections and comments which start with a # token. There is a coordinates section and then several element sections. To find the starting position of these element ...


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, ...


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

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 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 about changing the domain {x,0,b} and adding an "ExtrapolationHandler" to your NDSolve, as: sol = ParametricNDSolve[{y'[x] == b y[x], y[0] == 1}, y, {x, 0, b}, {b}, "ExtrapolationHandler" -> {Indeterminate&, "WarningMessage"->False}] Plot[Evaluate[Table[y[b][x] /. sol, {b, 0.1, 0.3, 0.1}]], {x, 0, 0.3}]


3

As far as I know, by the time the function you are mapping is evaluated the symbol names have already been substituted by their value. So an approach would be to work with the list of variable names (Names) and then evaluate them (Symbol) I think is better to work with a minimal working example, it's easier to follow. ListPlot3D[Symbol[#], PlotLabel -> ...


3

I would like to extend axis length a little bit to avoid the problem You can manually extend the plotted range using PlotRange Plot[x^2, {x, 0, 1}, AxesStyle -> Arrowheads[{0.03}], PlotRange -> {{0, 1.1}, {0, 1.1}}]


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

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]


2

sol = ParametricNDSolve[{y'[x] == b y[x], y[0] == 1}, y, {x, 0, 0.3}, {b}] Show@Table[Plot[y[b][x] /. sol, {x, 0, 0.6}], {b, {0.6, 0.4, 0.2}}] supplement You can plot it according to your needs. Show@Table[Plot[y[b][x] /. sol, {x, 0, b}], {b, {0.3, 0.2, 0.1}}] Plot[Evaluate[Table[y[b][x] /. sol, {b, {0.3, 0.2, 0.1}}]], {x, 0, 0.3}, PlotRange ...


2

Here's a functional solution to make a general 2-scale legend. Options[twoScaleLegend] = {"LegendOrientation" -> "Horizontal"}; twoScaleLegend[{xmin_, xmax_}, {label1_, label2_}, scale2_, opts : OptionsPattern[{twoScaleLegend, DensityPlot}]] := Module[{ticks, aspectratio, framelabel, ticklength}, ticklength = ...


2

I found a solution that is not general but working for me at the moment. Since I was looking for a simple linear scaling I just applied it to the range argument 1.8*{1, 100} + 32 in BarLegend Legended[ MatrixPlot[Table[i*j, {i, 1, 10}, {j, 1, 10}], ColorFunction -> (ColorData["SolarColors"][Rescale[#, {1, 100}]] &), ColorFunctionScaling ...



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