Preface


This is a tutorial made solely for the purpose of education and it was designed for students taking Applied Math 0330. It is primarily for students who have very little experience or have never used Mathematica before and would like to learn more of the basics for this computer algebra system. As a friendly reminder, don't forget to clear variables in use and/or the kernel.

Finally, the commands in this tutorial are all written in bold black font, while Mathematica output is in regular fonts. This means that you can copy and paste all comamnds into Mathematica, change the parameters and run them. You, as the user, are free to use the scripts to your needs for learning how to use the Mathematica program, and have the right to distribute this tutorial and refer to this tutorial as long as this tutorial is accredited appropriately.

Return to computing page for the first course APMA0330
Return to computing page for the second course APMA0340
Return to Mathematica tutorial for the second course APMA0330
Return to Mathematica tutorial for the first course APMA0340
Return to the main page for the course APMA0340
Return to the main page for the course APMA0330
Return to Part I of the course APMA0330

Plotting with filling


 

1.1.6. Plots with Filling


We repeat the previous example with filling:

ListLinePlot[{3, 4, 1, -2, 0, 3, 4, 1, 2}, Filling -> Axis]

 

Plot[2 - 2*x, {x, 0, 1}, FillingStyle -> Green, Filling -> Bottom]

Plot[{2, (x/3)}, {x, 0, 6}, Filling -> {1 -> {2}}, FillingStyle -> LightCyan]

Plot[{x, x^2}, {x, 0, 1}, Filling -> {1 -> {2}}, FillingStyle -> Pink]

Show[PolarPlot[{1, 2}, {t, 0, Pi/4}], RegionPlot[ x^2 + y^2 >= 1 && x^2 + y^2 <= 4 && y/x <= 1, {x, 0, 2}, {y, 0, 2}, ColorFunction -> "DarkRainbow"]]

Plot[{-1, 2}, {x, 1, 3}, Filling -> {1 -> {2}}, FillingStyle -> Purple, AspectRatio -> Automatic, AxesOrigin -> {0, 0}]

RegionPlot[{x^2 + y^2 <= 9}, {x, -3, 3}, {y, -3, 3}, PlotStyle -> LightBrown]

Plot[{3, (x/2) - 1}, {x, 0, 2}, Filling -> {1 -> {2}}, FillingStyle -> Yellow]

Show[PolarPlot[{1, 2}, {t, Pi/2, Pi}], RegionPlot[x^2 + y^2 >= 1 && x^2 + y^2 <= 4, {x, -2, 0}, {y, 0, 2}, ColorFunction -> "Rainbow"]]

tr = Plot[{1., Max[1, Min[2 x + 1, 4 - x]]}, {x, 0, 3}, AspectRatio -> 1/2, Ticks -> {{0, 1, 2, 3}, {0, 1, 2, 3}},
Filling -> Axis, FillingStyle -> Blue, Axes -> True, AxesStyle -> Directive[Thick]]

a = Graphics[{{Opacity[0], White, tr[[1]]}, GeometricTransformation[{Opacity[1], Blue, tr[[1]]}, TranslationTransform[{0, 1}]]}]

Show[a, Axes -> True, AxesStyle -> Black, AspectRatio -> 0.75]

 

RegionPlot[Sin[x y] > 0, {x, -1, 1}, {y, -1, 1},
FrameTicksStyle -> Directive[FontOpacity -> 0, FontSize -> 0]]
When plotting, you still see frameticks data:
rp = RegionPlot[x^2 + y^3/4 < 2 && x + y < 1, {x, -2, 2}, {y, -2, 2}, FrameTicks -> Automatic]
First extract the frameticks information and change the labels to blank:
newticks = Last@First[AbsoluteOptions[rp, FrameTicks]];
While Mathematica complains about that Ticks: {Automatic,Automatic} is not a valid tick specification, it still does its job. next we type:
Show[rp, FrameTicks -> newticks]
You may also try
newticks = Last@First[AbsoluteOptions[rp, FrameTicks]]; newticks[[All, All, 2]] = "";
but Mathematica will complain again and out will be the same.

RegionPlot[1 < Abs[x + I y] < 2, {x, -2, 2}, {y, -2, 2}, ImagePadding -> 1]
Another example:
Graphics3D[{Texture[img], EdgeForm[], Cylinder[{{0, 0, 0}, {0, 0, 2 Pi}}, 1]}, Boxed -> False]
We plot half of the polygon:
poly = Polygon[Table[N[{Cos[n *Pi/6], Sin[n*Pi/6]}], {n, 0, 6}]]
Graphics[{RGBColor[0.3, 0.5, 1], EdgeForm[Thickness[0.01]], poly}]
Show[%, Frame -> True]

 

 

 

 

I. Venn Diagrams


Filling circles can be plotted using Graphics cammand. Graphics are represented as symbolic expressions, using
either"directives" or "styles":

Graphics[{Blue, Disk[{0, 0}], Opacity[0.7], Pink, Disk[{1, 0}]}]

Graphics[{Style[Disk[{0, 0}], Green], Opacity[0.5], Pink, Disk[{1, 0}]}]

 

We can plot Venn diagrams using the following subroutine

 

VennDiagram2[n_, ineqs_: {}] :=
Module[{i, r = .6, R = 1, v, grouprules, x, y, x1, x2, y1, y2, ve},
v = Table[Circle[r {Cos[#], Sin[#]} &[2 Pi (i - 1)/n], R], {i, n}];
{x1, x2} = {Min[#], Max[#]} &[ Flatten@Replace[v, Circle[{xx_, yy_}, rr_] :> {xx - rr, xx + rr}, {1}]];
{y1, y2} = {Min[#], Max[#]} &[ Flatten@Replace[v, Circle[{xx_, yy_}, rr_] :> {yy - rr, yy + rr}, {1}]];
ve[x_, y_, i_] := v[[i]] /. Circle[{xx_, yy_}, rr_] :> (x - xx)^2 + (y - yy)^2 < rr^2;
grouprules[x_, y_] = ineqs /. Table[With[{is = i}, Subscript[_, is] :> ve[x, y, is]], {i, n}];
Show[If[MatchQ[ineqs, {} | False], {}, RegionPlot[grouprules[x, y], {x, x1, x2}, {y, y1, y2}, Axes -> False]],
Graphics[v], PlotLabel -> TraditionalForm[Replace[ineqs, {} | False -> \[EmptySet]]], Frame -> False]]

Then we plot two Venn diagrams:

a12 = VennDiagram2[2, Subscript[A, 1] && Subscript[A, 2]]
a1 = Graphics[Text[dogs, {-0.9, 0}]]
b1 = Graphics[Text[brown, {0.9, 0}]]
Show[a12, a1, b1]

or

a32 = VennDiagram2[2, Not[Subscript[A, 1]] && Subscript[A, 2]]
a33 = VennDiagram2[2, Not[Not[Subscript[A, 1]] && Subscript[A, 2]]]

   

 

 

Discontinuous Functions

Direction Fields

Implicit Plot

Parametric Plot

Labeling Figures

Figures with Arrows

Electric circuits

Plotting with Filling

Polar Plots

Some Famous Curves

Cycloids