Combine 2 plots in one [closed]

$f: R^2 -> R,$ $f(x,y)=x²-y²$

VectorPlot[{2 x, -2 y}, {x, -3, 3}, {y, -3, 3}]
ContourPlot[x^2 - y^2, {x, -3, 3}, {y, -3, 3}, ColorFunction -> "DeepSeaColors",
PlotLegends -> Automatic]


I want both plots (VectorPlot and ContourPlot) shown in one figure. How to approach this ?

• Take a look at Show. – Kuba May 19 '15 at 8:07
• have a look at Show – glS May 19 '15 at 8:08
• Please, if possible close this as a duplicate since it has surely been asked before. That will assist me in correctly applying the faq tag. – Mr.Wizard May 19 '15 at 9:12

Try this

PIC1 = VectorPlot[{2 x, -2 y}, {x, -3, 3}, {y, -3, 3}];
PIC2 = ContourPlot[x^2 - y^2, {x, -3, 3}, {y, -3, 3},
ColorFunction -> "DeepSeaColors", PlotLegends -> Automatic];
Show[PIC2, PIC1]


Try the Epilog option

ContourPlot[z, {x, -3, 3}, {y, -3, 3},
Epilog ->
First@
VectorPlot[Evaluate@Grad[z, {x, y}], {x, -3, 3}, {y, -3, 3}]
]


The output of the Plot commands are Graphics objects which are by default shown graphically by the notebook interface -- but you are free to collect it and do other stuff.

Also, since you seem to be new to Mathematica: You can use Grad to compute the gradient.

z = x^2 - y^2;
Show[{
ContourPlot[z, {x, -3, 3}, {y, -3, 3}],
VectorPlot[Evaluate@Grad[z, {x, y}], {x, -3, 3}, {y, -3, 3}]
}]


The Evaluate inside the VectorPlot tells Mathematica to evaluate this expression before starting to plot. Otherwise Mathematica would substitute specific values for x and y first, after which the gradient doesn't make much sense.