# Combine 2 plots in one [closed]

f:R2−>R,f: R^2 -> R, f(x,y)=xÂ²−yÂ²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 ?

=================

=================

3

=================

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]

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.

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}]
]