删除轮廓图上的边线 [英] Removing the edge line on a contour plot
问题描述
我使用Matlab创建极坐标并将其转换为笛卡尔坐标.
I used Matlab to create a polar coordinate and converted it into Cartesian coordinate.
[th,r] = meshgrid((0:0.5:360)*pi/180,0:.02:1);
[X,Y] = pol2cart(th,r);
我在此网格上获取数据并在其上生成一个contourf
图.
I get data on this mesh and produce a contourf
plot over it.
我的问题是我在我的轮廓线图中得到了一条中心线,我想删除该中心线,这可以对我有所帮助
My problem is that I get a center line in my contourf plot which I would like to remove, could some help me with this
谢谢
推荐答案
如果我稍微扩展一下您的示例以获取可以绘制的内容,我会重现该问题:
If I extend a little bit your example to get something I can plot, I do reproduce the problem:
[th,r] = meshgrid((0:0.5:360)*pi/180,0:.02:1);
[X,Y] = pol2cart(th,r);
Z = sqrt( X.^2 + Y.^2 ) ;
isoLevel = 0:0.1:10 ;
[C ,hc] = contourf(X,Y,Z,isoLevel) ;
界面上的黑线是因为函数contourf
创建patch
对象,并且这些对象趋向于自身闭合"(它们将在其轮廓中定义的第一个点和最后一个点之间创建一条线).
The black line at the interface is because the function contourf
create patch
objects and these objects tend to "close" themselves (they will create a line between the first and last point defined in their profile).
如果未在360度上完成轮廓的定义,则更易于观察.右图显示了相同的示例,但只有0:350
中的网格,并且LineStyle
设置为:
.
This is easier to observe if you do not complete the definition of your profile over 360 degrees. The picture on the right shows you the same example but with the grid only from 0:350
and with the LineStyle
set to :
.
如您所见,很难控制Matlab如何实际呈现此特定配置文件限制.有一些方法可以控制patch
对象的特定边缘,但是在这种情况下,它将涉及到检索每个补丁对象的句柄(在我的情况下为10,在更复杂的情况下为更多),找到要控制的边缘并基本上重新定义补丁(每个补丁).您最好自己从头开始绘制补丁.
As you can see, it is difficult to control how Matlab will actually render this specific profile limit. There are ways to control specific edges of patch
objects but in this case it would involve retrieving the handle of each patch object (10 in my case but many more in more complex cases), locating the edge you want to control and basically redefining the patch (each of them). You'd be better off drawing the patches from scratch yourself.
幸运的是,有一个简单的方法可以解决:摆脱所有面片边缘线...
Fortunately, there is a simple ways out of that: Get rid of all the patch edge lines...
但是那样您可能会错过您的等值线!没问题,只需将其绘制在补丁顶部即可! 您将获得所有有色补丁(无边框)和一组完全控制的( iso )线.
but then you may miss your isolines! No problem, just plot them on top of the patches ! You get all your colored patches (with no border) and a set of (iso)lines over which you have full control.
两种无需线的补丁的简单方法(i)将阴影设置为shading flat
,或(ii)在contourf
函数的参数中指定'EdgeColor','none'
.
Two easy way to get you patch without lines (i) set the shading to shading flat
, or (ii) specify 'EdgeColor','none'
in the parameter of the contourf
function.
要使用等值线,请使用姐妹函数contour
.
To get your isolines on top, use the sister contour
function.
因此,使用与以前相同的X
,Y
和Z
数据:
So using the same X
,Y
and Z
data than previously:
isoLevel = 0:0.1:10 ;
[C ,hc] = contourf(X,Y,Z,isoLevel,'EdgeColor','none') ; %// set of patches without border
% shading flat %// use that if you didn't specify ('EdgeColor','none') above
hold on
[C2 ,hc2] = contour(X,Y,Z,isoLevel,'LineColor','k') ; %// now get your isolines
将呈现:
如果要修改等值线属性(颜色,样式,厚度等),最好存储手柄hc2
.
It's a good idea to store the handle hc2
in case you want to modify your isolines properties (color, style, thicknes etc ...).
此外,建议指定等值线水平.这样,您可以确保contour
和contourf
都将使用相同的等值集.如果没有此功能,它可能会起作用(因为基础数据集是相同的),但个人而言,我总是更倾向于明确且不依赖于背景计算.
Also, specifying the isoline levels is recommended. This way you can make sure both contour
and contourf
will use the same set of isovalues. It could probably work without this (because the underlying dataset is the same), but personally I always prefer to be explicit and not rely on background calculations.
这篇关于删除轮廓图上的边线的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!