Skip to main content
replaced http://mathematica.stackexchange.com/ with https://mathematica.stackexchange.com/
Source Link

To get the fine control over the graphics, I would one probably has to construct each element and combine them. As @Silvia@Silvia points out, exclusions cause separate polygons to be created. When rendered on a discrete screen, these may overlap or have gaps.

That means drawing the step curve and its filling separately, like this:

Plot[Sign[Sin[x]] Ceiling[Abs[Sin[x]], 1/3], {x, -2 Pi, 2 Pi}, 
  PlotStyle -> Red],
Plot[Sign[Sin[x]] Ceiling[Abs[Sin[x]], 1/3], {x, -2 Pi, 2 Pi}, 
  PlotStyle -> None, Filling -> Axis,
  FillingStyle -> Directive[Opacity[0.2], Red], Exclusions -> None]

If you don't want to copy, paste, and edit each step function plot, you could write a function to combine both plots, such as the following:

SetAttributes[plotWithFilling, HoldAll];
plotWithFilling[Plot[f_, x_, opts___], col_] :=
  Show[
   Plot[f, x, PlotStyle -> col, opts],
   Plot[f, x, PlotStyle -> None, Filling -> Axis, 
    FillingStyle -> Directive[Opacity[0.2], col], Exclusions -> None, opts]];

Usage:

Show[
 Plot[Sin[x], {x, -2 Pi, 2 Pi}, PlotStyle -> Blue],
 plotWithFilling[
  Plot[Sign[Sin[x]] Ceiling[Abs[Sin[x]], 1/3], {x, -2 Pi, 2 Pi}],
  Red
  ],
 plotWithFilling[
  Plot[Sign[Sin[x]] Floor[Abs[Sin[x]], 1/3], {x, -2 Pi, 2 Pi}],
  Green
  ],
 AspectRatio -> 1/Pi, Frame -> False]

Mathematica graphics

To get the fine control over the graphics, I would one probably has to construct each element and combine them. As @Silvia points out, exclusions cause separate polygons to be created. When rendered on a discrete screen, these may overlap or have gaps.

That means drawing the step curve and its filling separately, like this:

Plot[Sign[Sin[x]] Ceiling[Abs[Sin[x]], 1/3], {x, -2 Pi, 2 Pi}, 
  PlotStyle -> Red],
Plot[Sign[Sin[x]] Ceiling[Abs[Sin[x]], 1/3], {x, -2 Pi, 2 Pi}, 
  PlotStyle -> None, Filling -> Axis,
  FillingStyle -> Directive[Opacity[0.2], Red], Exclusions -> None]

If you don't want to copy, paste, and edit each step function plot, you could write a function to combine both plots, such as the following:

SetAttributes[plotWithFilling, HoldAll];
plotWithFilling[Plot[f_, x_, opts___], col_] :=
  Show[
   Plot[f, x, PlotStyle -> col, opts],
   Plot[f, x, PlotStyle -> None, Filling -> Axis, 
    FillingStyle -> Directive[Opacity[0.2], col], Exclusions -> None, opts]];

Usage:

Show[
 Plot[Sin[x], {x, -2 Pi, 2 Pi}, PlotStyle -> Blue],
 plotWithFilling[
  Plot[Sign[Sin[x]] Ceiling[Abs[Sin[x]], 1/3], {x, -2 Pi, 2 Pi}],
  Red
  ],
 plotWithFilling[
  Plot[Sign[Sin[x]] Floor[Abs[Sin[x]], 1/3], {x, -2 Pi, 2 Pi}],
  Green
  ],
 AspectRatio -> 1/Pi, Frame -> False]

Mathematica graphics

To get the fine control over the graphics, I would one probably has to construct each element and combine them. As @Silvia points out, exclusions cause separate polygons to be created. When rendered on a discrete screen, these may overlap or have gaps.

That means drawing the step curve and its filling separately, like this:

Plot[Sign[Sin[x]] Ceiling[Abs[Sin[x]], 1/3], {x, -2 Pi, 2 Pi}, 
  PlotStyle -> Red],
Plot[Sign[Sin[x]] Ceiling[Abs[Sin[x]], 1/3], {x, -2 Pi, 2 Pi}, 
  PlotStyle -> None, Filling -> Axis,
  FillingStyle -> Directive[Opacity[0.2], Red], Exclusions -> None]

If you don't want to copy, paste, and edit each step function plot, you could write a function to combine both plots, such as the following:

SetAttributes[plotWithFilling, HoldAll];
plotWithFilling[Plot[f_, x_, opts___], col_] :=
  Show[
   Plot[f, x, PlotStyle -> col, opts],
   Plot[f, x, PlotStyle -> None, Filling -> Axis, 
    FillingStyle -> Directive[Opacity[0.2], col], Exclusions -> None, opts]];

Usage:

Show[
 Plot[Sin[x], {x, -2 Pi, 2 Pi}, PlotStyle -> Blue],
 plotWithFilling[
  Plot[Sign[Sin[x]] Ceiling[Abs[Sin[x]], 1/3], {x, -2 Pi, 2 Pi}],
  Red
  ],
 plotWithFilling[
  Plot[Sign[Sin[x]] Floor[Abs[Sin[x]], 1/3], {x, -2 Pi, 2 Pi}],
  Green
  ],
 AspectRatio -> 1/Pi, Frame -> False]

Mathematica graphics

Source Link
Michael E2
  • 244.8k
  • 18
  • 351
  • 774

To get the fine control over the graphics, I would one probably has to construct each element and combine them. As @Silvia points out, exclusions cause separate polygons to be created. When rendered on a discrete screen, these may overlap or have gaps.

That means drawing the step curve and its filling separately, like this:

Plot[Sign[Sin[x]] Ceiling[Abs[Sin[x]], 1/3], {x, -2 Pi, 2 Pi}, 
  PlotStyle -> Red],
Plot[Sign[Sin[x]] Ceiling[Abs[Sin[x]], 1/3], {x, -2 Pi, 2 Pi}, 
  PlotStyle -> None, Filling -> Axis,
  FillingStyle -> Directive[Opacity[0.2], Red], Exclusions -> None]

If you don't want to copy, paste, and edit each step function plot, you could write a function to combine both plots, such as the following:

SetAttributes[plotWithFilling, HoldAll];
plotWithFilling[Plot[f_, x_, opts___], col_] :=
  Show[
   Plot[f, x, PlotStyle -> col, opts],
   Plot[f, x, PlotStyle -> None, Filling -> Axis, 
    FillingStyle -> Directive[Opacity[0.2], col], Exclusions -> None, opts]];

Usage:

Show[
 Plot[Sin[x], {x, -2 Pi, 2 Pi}, PlotStyle -> Blue],
 plotWithFilling[
  Plot[Sign[Sin[x]] Ceiling[Abs[Sin[x]], 1/3], {x, -2 Pi, 2 Pi}],
  Red
  ],
 plotWithFilling[
  Plot[Sign[Sin[x]] Floor[Abs[Sin[x]], 1/3], {x, -2 Pi, 2 Pi}],
  Green
  ],
 AspectRatio -> 1/Pi, Frame -> False]

Mathematica graphics