PNG as figure background

442 ビュー (過去 30 日間)
Andrew McCall
Andrew McCall 2017 年 9 月 24 日
編集済み: Kristina Collins 2021 年 8 月 29 日
I am trying to generate a figure window with a saved PNG as the background. It will have a fluid simulation on top of it and all I want to do it have this saved PNG be the background. Similar to what set(gca,'Color', k) would do but instead of having the color I want to have it be a figure. Any thoughts?

採用された回答

Chad Greene
Chad Greene 2017 年 9 月 24 日
編集済み: Chad Greene 2017 年 9 月 24 日
Try this. Start by plotting whatever data you have, then load the png image and plot it with image. Use the limits of the current axes (by xlim and ylim) as the x,y coordinates of the image edges. Some images might be flipped in the vertical direction, so you may have to use -ylim when you call imagesc. The uistack call just sends the image down to the bottom of the stack.
x = 1:500;
y = sind(x);
plot(x,y,'linewidth',3)
axis tight;
hold on
I = imread('peppers.png');
h = image(xlim,-ylim,I);
uistack(h,'bottom')
  2 件のコメント
Mahmud Khan
Mahmud Khan 2018 年 11 月 2 日
How would it work for a 3D figure though? What if I wanted to use similar images on all three planes (x-y, x-z & y-z)?
I've been trying but failing.
Kristina Collins
Kristina Collins 2021 年 8 月 29 日
編集済み: Kristina Collins 2021 年 8 月 29 日
Ah, so close to what I need....
I'm trying to plot some shaded values as a backdrop on a datetime plot. Any tips on how to get this to play nicely with datetime axes?
(Edit: Never mind. Figured out an alternative solution for my particular problem (adding shading to the background to denote another quantity - in this case, eclipse obscuration - using "fill." Breadcrumb for anyone with a similar issue: https://www.mathworks.com/matlabcentral/answers/302892-use-fill-in-a-datetime-value-plot-to-color-the-background)

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

その他の回答 (2 件)

Marijn Dekker
Marijn Dekker 2019 年 12 月 10 日
@Chad Greene your answer works, however instead of using -ylim you would want to use flip(ylim) for a general case :)

Image Analyst
Image Analyst 2017 年 9 月 24 日

カテゴリ

Help Center および File ExchangeAxis Labels についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by