Get the facecolor of a contourf plot

30 ビュー (過去 30 日間)
Giorgos Papakonstantinou
Giorgos Papakonstantinou 2014 年 3 月 10 日
コメント済み: Johannes Korsawe 2015 年 1 月 26 日
I would like to find the facecolor of the the contourf patches. For example if :
[X,Y,Z] = peaks;
figure
contourf(X,Y,Z,4)
I would like to get the 5 different facecolors of the patches of the contour.
Thank you

回答 (1 件)

Doug Hull
Doug Hull 2014 年 3 月 11 日
[X,Y,Z] = peaks;
[l, h] = contourf(X,Y,Z,4)
hp = get(h,'children')
get(hp,'cdata')
colorbar
This gets you the value of the cdata. Look at the colormap to get the actual RGB color. Look at the colorbar to see what those values correspond to.
  5 件のコメント
Kelly Kearney
Kelly Kearney 2015 年 1 月 12 日
On the plus side, the new version stores the exact color value, so you don't need to use the color interpolation trick. On the down side, the properties are buried under a few layers of undocumented properties, so this may change down the road:
[X,Y,Z] = peaks;
[l, h] = contourf(X,Y,Z,4);
rgba = double(cat(2, h.FacePrims.ColorData))./255;
col = rgba(1:3,:)';
Johannes Korsawe
Johannes Korsawe 2015 年 1 月 26 日
Kelly, is there some undocumented chance for some magic to set some FaceAlpha-Values for the plotted areas of the contourf-command?

サインインしてコメントする。

カテゴリ

Help Center および File ExchangeContour Plots についてさらに検索

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by