本文介绍了Matlab图的自定义标记的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我搜索了google,每个人都说它不受支持.我想知道是否有任何开放的社区matlab函数能够将用户定义的png绘制为标记.我找到的最接近的是 http://de.mathworks.com /matlabcentral/fileexchange/39487-custom-marker-plot/content/plotCustMark/plotCustMark.m .但这达不到预期的目的.让我知道是否有可能为此写点东西!谢谢.

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 washttp://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.

其他问题:好的,我现在有这个奇怪的问题.我的png有黑色背景!我不明白为什么.我试图降低Alpha值仍然不起作用.

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.

解决方案:我在@brainkz的评论中提到的问题可以通过以下方式解决

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');

并随后设置

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.

推荐答案

imagesc可以将png放在您的绘图上.我们可以通过以下方式来利用这一点:

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

定义用户数据:

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

加载标记图片:

marker = imread('icon.png');

定义标记大小并调整xy数据:

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:

要获得所需的外观,您需要使用参数一段时间.

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

希望有帮助

这篇关于Matlab图的自定义标记的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-11 16:17