Message Boards Message Boards

Selectively plotting functions using Manipulate

Posted 9 years ago

Hi there,

I'd like to plot the solution region to a system of linear equations, but I want to be able to plot one equation at a time (and then "layer" them) instead of all at once. I'm having trouble figuring out how to do that using the Manipulate function. Do I use CheckboxBar? Here's what I have so far:

points1 := Table[{i - 1, j - 1}, {i, 70}, {j, 70}]
Show[ListPlot[points1, PlotRange -> {{0, 70}, {0, 70}}, ImageSize -> 850,  AxesLabel -> {"Racing Cars", "Sport-Utility Cars"}, PlotStyle -> 
   Directive[RGBColor[0.45, 0.67, 0.82, 0.82], PointSize[0.005]], LabelStyle -> Medium],
   RegionPlot[{R <= 40, S <= 60, R + S >= 70}, {R, 0, 70}, {S, 0, 70}, 
   PlotLegends -> "Expressions"]]

What I don't want is to have the ability to plot only one equation at a time. E.g.,

Manipulate[
 Plot[function[frequency*x + phase], {x, -6.6, 6.6}], {frequency, 1, 
  5}, {phase, 1, 10}, {function, {Sin, Cos, Tan}}]

(Sorry, newbie here... I promise that I did do a thorough Google search, but none of the examples I found have been helpful to my situation.)

Many thanks!

POSTED BY: Ilona
5 Replies
Posted 9 years ago

Just one more question: although your solution works like a charm at selectively plotting the different functions, it doesn't show the Plot Legend for the first function plotted (but it works fine for all cases thereafter). Is there a way to fix this?

Thanks again!

case 1

case 2

POSTED BY: Ilona

Use PlotLegends -> "AllExpressions" - there is example in docs for PlotLegends.

POSTED BY: Vitaliy Kaurov
Posted 9 years ago

Wow, I can't believe how simple that is. Thanks so much!

I'm just wondering if you'd be able to point me to where I would have gotten that idea in the documentation, because I thought I had read Manipulate and TogglerBar pretty thoroughly. Or even if you could explain what exactly is going on.

Is this the case I'm using?

manipulate

POSTED BY: Ilona

Manipulate doc page has list of tutorials at the bottom. A must read:

POSTED BY: Vitaliy Kaurov

What you need is TogglerBar:

points1 := Table[{i - 1, j - 1}, {i, 70}, {j, 70}]

Manipulate[

 Show[

  ListPlot[points1, PlotRange -> {{0, 70}, {0, 70}}, AxesLabel -> {"Racing Cars", "Sport-Utility Cars"}, 
   PlotStyle -> Directive[RGBColor[0.45, 0.67, 0.82, 0.82], PointSize[0.005]], LabelStyle -> Medium],

  RegionPlot[r, {R, 0, 70}, {S, 0, 70}, PlotLegends -> "Expressions"], ImageSize -> 500]

 , {{r, {R <= 40, R + S >= 70}}, {R <= 40, S <= 60, R + S >= 70}, TogglerBar}]

enter image description here

POSTED BY: Vitaliy Kaurov
Reply to this discussion
Community posts can be styled and formatted using the Markdown syntax.
Reply Preview
Attachments
Remove
or Discard

Group Abstract Group Abstract