Group Abstract Group Abstract

Message Boards Message Boards

0
|
4.4K Views
|
7 Replies
|
0 Total Likes
View groups...
Share
Share this post:

Unexpected output from plotting a stream function with ContourPlot?

Posted 3 years ago

Hi, I am trying to contourplot a stream function

ClearAll["Global`*"];
\[Psi] = 1/-288 (4 r - 9 r^3 + 6 r^5 - r^7) Cos[\[Alpha]];
ContourPlot[
 \[Psi] /. {r -> Norm[{x, y}], \[Alpha] -> ArcTan[y, x]}, {x, -1, 
  1}, {y, -1, 1},
 RegionFunction -> (Norm[{#, #2}] <= 1 &),
 Frame -> False,
 ContourShading -> None,
 Axes -> False,
 PlotLegends -> 
  BarLegend[Automatic, 9, LabelStyle -> {FontSize -> 24, Black}],
 Contours -> 30,
 ImageSize -> Large,
 ContourLabels -> {Style[Text[#3, {#1, #2}], 15] &, 
   Tooltip[#3, #2, TooltipStyle -> FontSize -> 10] &}
 ]

The output is
enter image description here

however the same contour is generated in a journal like this
enter image description here
I think it is not drawing the zero line. Also i want to draw the arrows as in the fig 2

POSTED BY: KRISHAN SHARMA
7 Replies
Posted 3 years ago

Thanks.

POSTED BY: KRISHAN SHARMA
Posted 3 years ago

I have found a workaround for the bug. You can download the updated package from my site http://www.dimi.uniud.it/gorni/Mma. Also, in your code I think it is better to move Style inside Text, instead of outside:

\[Psi] = 1/-288 (4 r - 9 r^3 + 6 r^5 - r^7) Cos[\[Alpha]];
ctrs = {.0037, .0035, .003, .002, .001, .0005, .000137};
ContourPlot[
 Evaluate[\[Psi] /. {r -> Norm[{x, y}], \[Alpha] -> ArcTan[y, x]} /. 
   Abs -> Identity], {x, -1, 1}, {y, -1, 1}, Oriented -> True, 
 ArrowShaftLength -> .01, RegionFunction -> (Norm[{#, #2}] <= 1 &), 
 Frame -> False, ContourShading -> None, Axes -> False, 
 ContourLabels -> {Text[Style[#3, 15], {#1, #2}] &, 
   Tooltip[#3, #2, TooltipStyle -> FontSize -> 10] &}, 
 ContourStyle -> Directive[{Black, Arrowheads[.02]}], 
 Contours -> Join[ctrs, -ctrs], Epilog -> Circle[], 
 ImageSize -> Large]
POSTED BY: Updating Name

Yes, I noticed them, and I don't know where they are coming from. My only suggestion is to change your code until they go away.

POSTED BY: Gianluca Gorni
Posted 3 years ago

Thanks its working. but as i am increasing the text size in contourlabel some absurd text are coming at the center of contour.

ClearAll["Global`*"];
\[Psi] = 1/-288 (4 r - 9 r^3 + 6 r^5 - r^7) Cos[\[Alpha]];
ctrs = {.0037, .0035, .003, .002, .001, .0005, .000137};
ContourPlot[
 Evaluate[\[Psi] /. {r -> Norm[{x, y}], \[Alpha] -> ArcTan[y, x]} /. 
   Abs -> Identity], {x, -1, 1}, {y, -1, 1},
 Oriented -> True,
 RegionFunction -> (Norm[{#, #2}] <= 1 &),
 Frame -> False,
 ContourShading -> None,
 Axes -> False,
 ContourLabels -> {Style[Text[#3, {#1, #2}], 15] &, 
   Tooltip[#3, #2, TooltipStyle -> FontSize -> 10] &},
 ContourStyle -> Directive[{Black, Arrowheads[.02]}],
 Contours -> Join[ctrs, -ctrs],
 Epilog -> Circle[],
 ImageSize -> Large
 ]

enter image description here

POSTED BY: KRISHAN SHARMA

I don't know how to add labels to a StreamPlot. With my package CurvesGraphics you can do like this:

\[Psi] = 1/-288 (4 r - 9 r^3 + 6 r^5 - r^7) Cos[\[Alpha]];
ctrs = {.0037, .0035, .003, .002, .001, .0005, .000137};
ContourPlot[
 Evaluate[\[Psi] /. {r -> Norm[{x, y}], \[Alpha] -> ArcTan[y, x]} /. 
   Abs -> Identity], {x, -1, 1}, {y, -1, 1}, Oriented -> True, 
 RegionFunction -> (Norm[{#, #2}] <= 1 &), Frame -> False, 
 ContourShading -> None, Axes -> False, ContourLabels -> All, 
 ContourStyle -> Directive[{Black, Arrowheads[.03]}], 
 PlotLegends -> 
  BarLegend[Automatic, 9, LabelStyle -> {FontSize -> 24, Black}], 
 Contours -> Join[ctrs, -ctrs], Epilog -> Circle[], 
 ImageSize -> Large]
POSTED BY: Gianluca Gorni
Posted 3 years ago

Thanks Gianluca Gorni, Can I add the labels in the streamplot as it is given in the figure2.

POSTED BY: KRISHAN SHARMA

The circle is a contour line, but it is numerically unstable. You can add it as Epilog:

\[Psi] = 1/-288 (4 r - 9 r^3 + 6 r^5 - r^7) Cos[\[Alpha]];
Factor[\[Psi] /. {r -> Norm[{x, y}], \[Alpha] -> ArcTan[y, x]} /. 
  Abs -> Identity]
ctrs = {.0037, .0035, .003, .002, .001, .0005, .000137, 0};
ContourPlot[\[Psi] /. {r -> Norm[{x, y}], \[Alpha] -> 
    ArcTan[y, x]}, {x, -1, 1}, {y, -1, 1}, 
 RegionFunction -> (Norm[{#, #2}] <= 1 &), Frame -> False, 
 ContourShading -> None, Axes -> False, 
 PlotLegends -> 
  BarLegend[Automatic, 9, LabelStyle -> {FontSize -> 24, Black}], 
 Contours -> Join[ctrs, -ctrs], Epilog -> Circle[], 
 ImageSize -> Large, 
 ContourLabels -> {Style[Text[#3, {#1, #2}], 15] &, 
   Tooltip[#3, #2, TooltipStyle -> FontSize -> 10] &}]

As for the arrows, you can try with StreamPlot:

StreamPlot[
 Evaluate[{{0, 1}, {-1, 0}} . 
   D[\[Psi] /. {r -> Norm[{x, y}], \[Alpha] -> ArcTan[y, x]} /. 
     Abs -> Identity, {{x, y}}]], {x, -1, 1}, {y, -1, 1}, 
 RegionFunction -> (Norm[{#, #2}] <= 1 &), Frame -> False, 
 Axes -> False, Epilog -> Circle[], ImageSize -> Large]

or with the CurveGraphics package that you can find at my page http://www.dimi.uniud.it/gorni/Mma

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