# Discretize chart in a given interval

Using the following code:

plot = Plot[Sin[x], {x, -Pi, Pi}];
points = Cases[plot // Normal, Line[{x__}] -> x, Infinity];
ListPlot[points]


I get: Question: Is it possible to thicken such discretization? Also, you can do so at any given internal interval to the graph?

Thank you for your invaluable help.

EDIT:

To be honest I was wrong example, I try again.

plot = Show[Plot[Sin[x], {x, -Pi, Pi}]];
points = Cases[plot // Normal, Line[{x__}] -> x, Infinity];
ListPlot[points]


Here, in the latter case there is any hope to increase the points in a given interval, for example, in [-1,1]? Thanks again and sorry for my incompetence.

• "Thicken"? You mean, like increase the number of points? Try adding PlotPoints -> 200 or something to the Plot function: Plot[Sin[x], {x, -Pi, Pi}, PlotPoints -> 200]. As for doing it in particular intervals, you can always make multiple plots with different PlotPoints, and then Show them all together on one plot. – march Aug 3 '16 at 20:57
• You can control exactly the points plotted by creating the table yourself ListPlot[Table[{x,Sin[x]},{x,-Pi,Pi,2*Pi/(n-1)}]] where n is the number of points you want. – N.J.Evans Aug 3 '16 at 20:59
• Thanks a lot, always clear. Unfortunately I was wrong example, in the sense that in fact I have to solmanete available a "show", as shown above later. Can you help me anyway? Thank you. – TeM Aug 3 '16 at 21:06
• "increase the points in a given interval" - what do you need it for? – J. M.'s technical difficulties Aug 3 '16 at 21:06
• Maybe you would like Interpolation[points]? Look up the documentation for Interpolation. – march Aug 3 '16 at 21:54

Here one option is to add new points to increase density in a range.

The pointsInitial list is the values ​​you have in your points list. I've created a new list that creates new points for your given interval.

The Subdivide function controls how many points you want in the minimum and maximum limits. Then two controls were created for number of points.

The Join function joins these two lists

The Sort function organizes the values ​​in ascending order

The DeleteDuplicates function can delete duplicate values.

plot = Plot[Sin[x], {x, -Pi, Pi}];
pointsInitial = Flatten@{{#}, {Sin[#]}} & /@ Subdivide[-Pi, Pi, 100];
pointsAdditional = Flatten@{{#}, {Sin[#]}} & /@ Subdivide[-1, 1, 45];
ImageSize -> 500] You can also use Mesh as follows:

mesh = Join[Subdivide[-Pi, -1, 20],  Subdivide[-1, 1, 50], Subdivide[1,Pi, 20]]

Plot[Sin[x], {x, -Pi, Pi},
Mesh -> {mesh}, MeshStyle -> Red, PlotStyle -> None] In version 9 or earlier versions, you can define mesh using Range instead of Subdivide as follows:

mesh = Join @@ Range[{-Pi, -1, 1}, {-1, 1, Pi}, {(-1 + Pi)/20, 2/50, (Pi - 1)/20}]


Also (thanks: @MichaelE2 ):

ListPlot@Transpose@{mesh, Sin@mesh} • Also ListPlot@Transpose@{mesh, Sin@mesh}, plus styling as desired. – Michael E2 Jun 21 '17 at 21:27
• @Michael, thank you. I updated with your suggestion. – kglr Jun 21 '17 at 22:36

If you have a function density[x] which is proportional to the desired density of the sampling near x, then the following is a way to generate samples with the desired variable density:

Clear[x, t];
interval = {-Pi, Pi};
density[x_] :=     (* NDSolve does not detect the discontinuities in Piecewise here *)
SimplifyPWToUnitStep@Piecewise[{{3, -1 <= x <= 1}}, 1];   (* convert to UnitStep *)
samplingIFN = NDSolveValue[
{x'[t] == 1/density[x[t]], x == interval[],
WhenEvent[x[t] == interval[], "StopIntegration"]},
x, {t, 0, Infinity}];

domain = First@samplingIFN["Domain"];
xx = samplingIFN@Subdivide[Sequence @@ domain, 100];
ListPlot[Transpose@{xx, Sin@xx}] Assuming you just want a more even distribution of mesh points, another possibility is to use the "ArcLength" mesh function:

Plot[
Sin[x], {x,-Pi,Pi},
PlotStyle->None, MeshStyle->Blue, Mesh->100, MeshFunctions->{"ArcLength"}
]
` • I think the OP wants "to increase the points in a given interval, for example, in [-1,1]", i.e., increase the density. But since @Manu didn't accept any of those answers, maybe we're wrong. – Michael E2 Jun 22 '17 at 1:01