Plotting perpendicular lines to a contour plot (electric field from equipotential curves)
(1) Use Interpolation
to get an interpolating function intF
.
intF = Interpolation[Flatten[MapIndexed[{#2, #} &, Transpose@data, {2}], 1],
InterpolationOrder -> 7];
(2) Use intF
to get a ContourPlot
and a StreamPlot
(using the approach from
this answer by Michael E2 and combine the two plots with Show
:
cp = ContourPlot[intF[x, y], {x, 1, 15}, {y, 1, 8},
Contours -> Range[0, 7], AspectRatio -> Automatic, ImageSize -> Large];
sp = StreamPlot[Evaluate[-D[intF[x, y], {{x, y}}]], {x, 1, 15}, {y, 1, 8},
StreamScale -> None,
StreamStyle -> {"Arrow", Directive[Thick, Red]},
StreamPoints -> Fine, AspectRatio -> Automatic];
Show[cp, sp]
Due to @kgir 's response, I made it to get very decent results. I'd like to share it with you, in any case there's someone trying to do the same.
intF = Interpolation[
Flatten[MapIndexed[{#2, #} &, Transpose@data1, {2}], 1],
InterpolationOrder -> {1, 1}];
cp = ContourPlot[intF[x, y], {x, 1, 15}, {y, 0.9, 8},
Contours -> Range[0.1, 12], AspectRatio -> Automatic,
ImageSize -> Medium, PlotLegends -> {Automatic}];
sp = StreamPlot[
Evaluate[-D[intF[x, y], {{x, y}}]], {x, 1, 15}, {y, 1.5, 8} ,
StreamScale -> Coarse,
StreamStyle -> {"Arrow", Directive[Thin, Blue]},
StreamPoints -> Fine, AspectRatio -> Automatic,
VectorScale -> Automatic];
vp := VectorPlot[
Evaluate[-D[intF[x, y], {{x, y}}]], {x, 1, 15}, {y, 1.5, 5.9},
VectorScale -> Automatic, AspectRatio -> Automatic,
VectorStyle -> {LightGreen}, VectorPoints -> 15]
vp2 := VectorPlot[
Evaluate[-D[intF[x, y], {{x, y}}]], {x, 1, 15}, {y, 6.1, 8},
VectorScale -> Automatic, AspectRatio -> Automatic,
VectorStyle -> {LightGreen}, VectorPoints -> 15]
sp2 = MapAt[{Opacity[0.25], #} &, sp, 1];
Show[cp, vp, vp2, sp2]}
Show[%169, ImageSize -> Large, FrameLabel -> {"Posición en eje x (cm)",
HoldForm["Posición en eje y (cm)"], "", "valores de Voltaje (V)"}, Ticks ->
Automatic,FrameStyle -> Directive[Black, Thickness[Medium]],
LabelStyle -> {FontFamily->"Arial", 16, GrayLevel[0]}]
Results in: