2
$\begingroup$

And I want this plot to be discrete into 100 equal rectangulars which topmid of them have a line joined together.

Something like this, but for the mentioned equation:

Enter image description here

$\endgroup$
6
$\begingroup$

You can use the option Joined -> True in DiscretePlot:

DiscretePlot[x Sin[1/x]^2, {x, π/4, π, π/80}, 
 PlotStyle -> EdgeForm[{Thin, Gray}], 
 ColorFunction -> "Rainbow", 
 ExtentSize -> Full, 
 Joined -> True]

enter image description here

$\endgroup$
1
  • 1
    $\begingroup$ (+1) For large step sizes or unwieldy functions, the Joined option might not be sufficient, depending on your application. $\endgroup$
    – Chip Hurst
    Oct 22 at 0:36
4
$\begingroup$

One way is to combine stylized outputs from DiscretePlot and Plot:

Show[
  DiscretePlot[
    x Sin[1/x]^2, 
    {x, π/4, π, π/80}, 
    BaseStyle -> EdgeForm[Directive[AbsoluteThickness[0.75], GrayLevel[0.25]]],
    ColorFunction -> "Rainbow",
    ExtentSize -> Full, 
    PlotStyle -> AbsoluteThickness[0.75]
  ],
  Plot[
    x Sin[1/x]^2, 
    {x, π/4, π}, 
    PlotStyle -> Directive[AbsoluteThickness[0.75], Black]
  ]
]

enter image description here

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.