Translucent Markers on a Logarithmic Chart

I am trying to get translucent round markers on a log chart. MATLAB's own scatter graph function does not create translucent markers (see comments below), so I use this wonderful scatter_patches tool from Central File Sharing , and it works very well:

However, I am having problems adapting this code for the logarithm spread chart. To get a logarithmic logarithm plot with this program, I need to fix two things:

1. Change the axis to the log scale. This can be achieved by adding the following after line 61:

 set(cax, 'XScale', 'log'); set(cax, 'YScale', 'log'); 

This creates the correct scale and grid points.

2. However, after I recorded 1., the size of the markers was uneven in my plot. On the logarithmic plot, areas with lower axis values ​​are enlarged. In the scatter_patches graph, the markers on the lower side of the axes are larger, while they are smaller relative to the side with higher axis values. Thus, the size of the marker is not the same throughout the plot. I tried using log10(cSize) instead of cSize on lines 221-222, but that only reduced the difference between the maximum and smallest marker sizes. He did not give markers of the same size on the chart.

If anyone has an idea of ​​what I'm missing here, share it.

Any help would be greatly appreciated.

+5
source share
3 answers

Since Matlab R2014b everything has become very easy. No additional file sharing features are required, only some undocumented features . The basic idea is to get a hidden marker descriptor and apply a value of <1 for the last value in EdgeColorData to achieve the desired transparency.

Here we go:

 %// example data x = linspace(0,3*pi,200); y = cos(x) + rand(1,200); %// plot scatter, get handle h = scatter(x,y); drawnow; %// important %// get marker handle hMarkers = h.MarkerHandle; %// get current edge and face color edgeColor = hMarkers.EdgeColorData faceColor = hMarkers.FaceColorData %// set face color to the same as edge color faceColor = edgeColor; %// opacity opa = 0.3; %// set marker edge and face color hMarkers.EdgeColorData = uint8( [edgeColor(1:3); 255*opa] ); hMarkers.FaceColorData = uint8( [faceColor(1:3); 255*opa] ); 

enter image description here

+6
source

In case this helps, I wrote a set of Matlab functions for creating translucent markers on stories and legends. Files are available in MATLAB Central as MarkerTransparency . A few examples of how to use these features are included in the download, and there is also a Wiki on GitHub . The main advantage of this package is that it allows the user to receive translucent markers also in the legend. These features have not been tested for scatter plots, but can be easily adapted to suit your needs.

+1
source

On line 192, change the line as follows:

hh(end+1) = patch( exp(cSize * sin(patchSpec) / ptsPerXUnit + xs(i)), exp(cSize * cos(patchSpec) / ptsPerYUnit + ys(i)), cColor, cPatchArgs{:}); and it will work.

I just add exp()

Perform the same operation on lines 222 and 223!

Work like Anindya's charm;).

0
source

Source: https://habr.com/ru/post/1246623/


All Articles