グラフの背景に画像を表示させたい

25 views (last 30 days)
koji fukumoto
koji fukumoto on 3 Dec 2019
Answered: yuji Ito on 30 Jun 2020
お世話になります。
グラフ(axes)の背景にpng画像を、グラフの軸とは無関係に表示させたいです。
グラフに画像を表示する方法としては、imreadで読込んだイメージデータをimshowやimageを用いて表示する方法がありますが、これらはグラフの軸と画像のサイズ(縦横ピクセル数)が関係性を持ってしまい、例えば「X軸とY軸の最大値が100のグラフに、300x300ピクセルの画像を縮小せずに表示する」という事ができない認識です(X軸・Y軸が300まで拡張されてしまう)。
最終的にやりたいことは、背景画像が表示されているグラフ上をクリックし、クリックした点を直線で結ぶという処理です。
背景画像が無い状態で「クリックした点を直線で結ぶ」という実装はできておりますので、後はグラフに背景画像を表示させるだけです。
よろしくお願い致します。

Accepted Answer

Shunichi Kusano
Shunichi Kusano on 3 Dec 2019
画像をリサイズしてから表示するというのはどうでしょうか。
  2 Comments
Akira Agata
Akira Agata on 3 Dec 2019
Edited: Akira Agata on 3 Dec 2019
あるいは axes を2つ重ねて、画像とプロットをそれぞれ表示させたうえで、プロット側の axes の背景を透明にする、というのはどうでしょうか。以下は簡単なサンプルです。
% Sample image
I = imread('peppers.png');
figure
ax1 = axes;
ax2 = axes;
imshow(I,'Parent',ax1) % Show the image on ax1
plot(ax2,magic(4)) % Plot the data on ax2
ax2.Color = 'none'; % Set background color of ax2 to transparent
koji fukumoto
koji fukumoto on 3 Dec 2019
「axes を2つ重ねて」の方法で実現できました。
迅速なご回答、ありがとうございました。

Sign in to comment.

More Answers (1)

yuji Ito
yuji Ito on 30 Jun 2020
AppDesignerのplotウインドウで上記の様なことをしたいのですが、
ax1,ax2と2つの軸を作ることが出来ず、上記ではうまくいきません。
AppDesingerで同様のことを実現する方法はないでしょうか?

Products


Release

R2018a

Community Treasure Hunt

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

Start Hunting!