1

I want to plot two functions with different independent variables in one Plot.

The code below plots my functions in two different plots.

a = 0.67
b = 0.33
p=1
YB=(B* p)/a
YZ=(Z* p)/b
Plot[YB,{B,0,10}, PlotLabels ->"Y=(B* p)/0.67"]
Plot[YZ,{Z,0,10}, PlotLabels ->"Y=(Z* p)/0.33"]

How should I modify this code so that the plots be combined into one plot?

Alex97
  • 410
  • 2
  • 16
Macosso
  • 113
  • 6
  • 3
    Define them as functions first: Clear[yb]; yb[b_] := b p / 67 and do the same with yz[z_] := ... then plot them as function of the same variable. Or alternatively combine the two plots with Show[Plot[...], Plot[...]]. – MarcoB Dec 07 '21 at 13:54

1 Answers1

3

This is a possible solution:

YB = (B*p)/a;
YZ = (Z*p)/b;
labels = {"YB = (B*p)/a", "YZ = (p*Z)/b"};
p1 = Plot[bb, {bb, 0, 5}, PlotStyle -> Green, PlotLabels -> labels[[1]]];
p2 = Plot[2*aa, {aa, 0, 10}, PlotStyle -> Red,PlotLabels -> labels[[2]]];

Show[p1, p2, PlotRange -> Full]

The result is this:

enter image description here

The following links are useful:

How to | Combine Two or More Graphics

Plotting two functions in one graph

Wolfram documentation for Show[...]

Alex97
  • 410
  • 2
  • 16
  • PlotLabels is an option to Plot, not Graphics, so it doesn't do anything inside of Show. – Brett Champion Dec 07 '21 at 16:01
  • There is a problem with using PlotLabels as an argument of Show I have asked a question about it and I will correct the answer as soon as possible.https://mathematica.stackexchange.com/questions/259384/problem-with-using-plotlabels-or-plotlegends-as-an-option-for-show – Alex97 Dec 07 '21 at 16:01
  • I have edited the answer. but still one of the labels are not shown. I asked the problem here:https://mathematica.stackexchange.com/questions/259386/labels-not-shown-in-a-plot – Alex97 Dec 07 '21 at 16:11
  • I have finalized my answer and it works now. – Alex97 Dec 07 '21 at 17:13
  • 1
    Your solution was exactly what I wanted, I am really sorry for the moderator who found my answer off topic, I am really new to Mathematica, so I would appreciate if anybody would improve my question. – Macosso Dec 07 '21 at 22:35