Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
436 views
in Technique[技术] by (71.8m points)

Custom Markers for Matlab plot

I have searched google and everyone says its not supported. I was wondering if there are any open community matlab functions which would be able to plot a user defined png as a marker. The closest I found was http://de.mathworks.com/matlabcentral/fileexchange/39487-custom-marker-plot/content/plotCustMark/plotCustMark.m . But it doesn't serve the intended purpose . Let me know if its even possible for me to write something up for this ! Thanks.

Additional Problem : Okay I have this weird problem now . my png has a black background !! I dont understand why. I tried to lower the alpha value still doesn't work.

Solution : The problems I mentioned in the comments to @brainkz can be solved by

http://de.mathworks.com/matlabcentral/answers/144411-displaying-image-over-background-making-top-image-background-color-transparent

Method : Import the transparency settings of your image through

[marker,map,transperancy ] = imread('car.png');

and later set

handleIm = imagesc([x_low x_high], [y_low y_high], marker)
set(handleIm ,'AlphaData',transperancy);

Clarification : The images were all transperant but since I was overlaying it over another image it turned the current images background to default black. I posted a solution to this problem which I guess would be really useful to a lot of people.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

imagesc can put the png on you plot. We can avail ourselves of this in the following way:

Define user data:

x = 1:10;
y = 5*rand(size(x)) + 2.5;

Load the marker image:

marker = imread('icon.png');

Define marker size and adjust the x and y data:

markersize = [1,1]; %//The size of marker is expressed in axis units, NOT in pixels
x_low = x - markersize(1)/2; %//Left edge of marker
x_high = x + markersize(1)/2;%//Right edge of marker
y_low = y - markersize(2)/2; %//Bottom edge of marker
y_high = y + markersize(2)/2;%//Top edge of marker

Then, we put our loaded image on the plot at the specified points

for k = 1:length(x)
    imagesc([x_low(k) x_high(k)], [y_low(k) y_high(k)], marker)
    hold on
end
axis equal
hold off

At the end, you are likely to get the following:

enter image description here

To achieve the desired appearance, you would need to play with the parameters for a while.

Hope that helps


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...