Message Boards Message Boards

0
|
3544 Views
|
8 Replies
|
7 Total Likes
View groups...
Share
Share this post:

How to change the default graphic shape in ContourPlot output?

Posted 2 years ago

The density figure like this can be plotted in Python with Contour, and I can't do this with Mathematica in a elliptical shape. The same command Contour in Mathematica give a square picture, can Mathematica plot the same shape like Python?
And the picture is a simple example, the data can be chosen freely.

Attachment

POSTED BY: Tony Coliderse
8 Replies

Tony,

You need to plot over a region. For example,

DensityPlot[Sin[x + Cos[y]], {x, y} \[Element] Disk[{0, 0}, {6, 3}], 
 AspectRatio -> Automatic]

Gives

enter image description here

Regards,

Neil

POSTED BY: Neil Singer

If you want to do the mesh lines and other details, you can use more options. These make no sense to the plot because I just made things up and copied the MeshFunction from an example in the documentation to show you.

DensityPlot[Sin[x + Cos[y]], {x, y} \[Element] Disk[{0, 0}, {6, 3}], 
 AspectRatio -> Automatic, BoundaryStyle -> Directive[Red, Thick], 
 Frame -> None, Mesh -> 10, 
 MeshFunctions -> {Re[Sqrt[#1 + I #2]] &, Im[Sqrt[#1 + I #2]] &}]

gives

enter image description here

POSTED BY: Neil Singer
Posted 2 years ago

Thanks for your help! But if I want to do this with the data in a list shape, rather than a continous function. How to achieve it in this case? I read the documentation in detail, but can't solve it.

test = Table[{x, y, x + y}, {x, 0, 10}, {y, 0, 10}];
test = Flatten[test, 1];
ListDensityPlot[test,AspectRatio -> Automatic]
POSTED BY: Tony Coliderse

By the way, I with I knew why

ContourPlot[x, Element[{x, y}, Disk[]]]
Plot3D[x, Element[{x, y}, Disk[]]]

draw the plot on a disk, but the following does not:

ParametricPlot3D[{x, y, x}, Element[{x, y}, Disk[]]]

Actually, it did up to version 12.0. But then that capability was inexplicably removed.

POSTED BY: Gianluca Gorni

Tony,

Use RegionFunction to specify the region. For example, this specifies a ring:

ListDensityPlot[test, AspectRatio -> Automatic, 
 RegionFunction -> Function[{x, y, z}, 2 < x^2 + y^2 < 6]]

Regards

Neil

POSTED BY: Neil Singer

Gianluca,

This works:

ParametricPlot3D[{x, y, x}, Element[{x, y}, Disk[]], 
 RegionFunction -> Function[{x, y, z}, x^2 + y^2 < 1]]

or better yet,

ParametricPlot3D[{x, y, x}, Element[{x, y}, Disk[]], 
 RegionFunction -> Function[{x, y, z}, Element[{x, y}, Disk[]]]]

but you should report that the element syntax no longer automatically limits the region.

Regards

Neil

POSTED BY: Neil Singer

Yes, we can do it with RegionFunction, but it is not so convenient for Polygons, for example. The new behaviour of ParametricPlot3D is declared explicitly in the documentation, and I cannot report it as a bug, maybe as a complaint?

POSTED BY: Gianluca Gorni
Posted 2 years ago

Thank you sir! This way can help me solve this problem greatly!

Regards

Tony

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

Group Abstract Group Abstract