Undocumented Matlab
  • SERVICES
    • Consulting
    • Development
    • Training
    • Gallery
    • Testimonials
  • PRODUCTS
    • IQML: IQFeed-Matlab connector
    • IB-Matlab: InteractiveBrokers-Matlab connector
    • EODML: EODHistoricalData-Matlab connector
    • Webinars
  • BOOKS
    • Secrets of MATLAB-Java Programming
    • Accelerating MATLAB Performance
    • MATLAB Succinctly
  • ARTICLES
  • ABOUT
    • Policies
  • CONTACT
  • SERVICES
    • Consulting
    • Development
    • Training
    • Gallery
    • Testimonials
  • PRODUCTS
    • IQML: IQFeed-Matlab connector
    • IB-Matlab: InteractiveBrokers-Matlab connector
    • EODML: EODHistoricalData-Matlab connector
    • Webinars
  • BOOKS
    • Secrets of MATLAB-Java Programming
    • Accelerating MATLAB Performance
    • MATLAB Succinctly
  • ARTICLES
  • ABOUT
    • Policies
  • CONTACT

Plot markers transparency and color gradient

November 19, 2014 90 Comments

Last week I explained how to customize plot-lines with transparency and color gradient. Today I wish to show how we can achieve similar effects with plot markers. Note that this discussion (like the preceding several posts) deal exclusively with HG2, Matlab’s new graphics system starting with R2014b (well yes, we can also turn HG2 on in earlier releases).
As Paul has noted in a comment last week, we cannot simply set a 4th (alpha transparency) element to the MarkerFaceColor and MarkerEdgeColor properties:

>> x=1:10; y=10*x; hLine=plot(x,y,'o-'); drawnow;
>> hLine.MarkerFaceColor = [0.5,0.5,0.5];      % This is ok
>> hLine.MarkerFaceColor = [0.5,0.5,0.5,0.3];  % Not ok
While setting the 'MarkerFaceColor' property of Line:
Color value must be a 3 element numeric vector

Standard Matlab plot markers
Standard Matlab plot markers

Lost cause? – not in a long shot. We simply need to be a bit more persuasive, using the hidden MarkerHandle property:

>> hMarkers = hLine.MarkerHandle;  % a matlab.graphics.primitive.world.Marker object
>> hMarkers.get
    EdgeColorBinding: 'object'
       EdgeColorData: [4x1 uint8]
       EdgeColorType: 'truecolor'
    FaceColorBinding: 'object'
       FaceColorData: [4x1 uint8]
       FaceColorType: 'truecolor'
    HandleVisibility: 'off'
             HitTest: 'off'
               Layer: 'middle'
           LineWidth: 0.5
              Parent: [1x1 Line]
       PickableParts: 'visible'
                Size: 6
               Style: 'circle'
          VertexData: [3x10 single]
       VertexIndices: []
             Visible: 'on'
>> hMarkers.EdgeColorData'  % 4-element uint8 array
ans =
    0  114  189  255
>> hMarkers.FaceColorData'  % 4-element uint8 array
ans =
  128  128  128  255

>> hMarkers = hLine.MarkerHandle; % a matlab.graphics.primitive.world.Marker object >> hMarkers.get EdgeColorBinding: 'object' EdgeColorData: [4x1 uint8] EdgeColorType: 'truecolor' FaceColorBinding: 'object' FaceColorData: [4x1 uint8] FaceColorType: 'truecolor' HandleVisibility: 'off' HitTest: 'off' Layer: 'middle' LineWidth: 0.5 Parent: [1x1 Line] PickableParts: 'visible' Size: 6 Style: 'circle' VertexData: [3x10 single] VertexIndices: [] Visible: 'on' >> hMarkers.EdgeColorData' % 4-element uint8 array ans = 0 114 189 255 >> hMarkers.FaceColorData' % 4-element uint8 array ans = 128 128 128 255

As we can see, we can separately attach transparency values to the marker’s edges and/or faces. For example:

hMarkers.FaceColorData = uint8(255*[1;0;0;0.3]);  % Alpha=0.3 => 70% transparent red

hMarkers.FaceColorData = uint8(255*[1;0;0;0.3]); % Alpha=0.3 => 70% transparent red

70% Transparent Matlab plot markers
70% Transparent Matlab plot markers

And as we have seen last week, we can also apply color gradient across the markers, by modifying the EdgeColorBinding/FaceColorBinding from ‘object’ to ‘interpolated’ (there are also ‘discrete’ and ‘none’), along with changing the corresponding FaceColorData/EdgeColorData from being a 4×1 array to a 4xN array:

>> colorData = uint8([210:5:255; 0:28:252; [0:10:50,40:-10:10]; 200:-10:110])
colorData =
  210  215  220  225  230  235  240  245  250  255
    0   28   56   84  112  140  168  196  224  252
    0   10   20   30   40   50   40   30   20   10
  200  190  180  170  160  150  140  130  120  110
>> set(hMarkers,'FaceColorBinding','interpolated', 'FaceColorData',colorData)

>> colorData = uint8([210:5:255; 0:28:252; [0:10:50,40:-10:10]; 200:-10:110]) colorData = 210 215 220 225 230 235 240 245 250 255 0 28 56 84 112 140 168 196 224 252 0 10 20 30 40 50 40 30 20 10 200 190 180 170 160 150 140 130 120 110 >> set(hMarkers,'FaceColorBinding','interpolated', 'FaceColorData',colorData)

Matlab plot markers with color and transparency gradients
Matlab plot markers with color and transparency gradients

This can be useful for plotting comet trails, radar/sonar tracks, travel trajectories, etc. We can also use it to overlay meta-data information, such as buy/sell indications on a financial time-series plot. In fact, it opens up Matlab plots to a whole new spectrum of customizations that were more difficult (although not impossible) to achieve earlier.
Throughout today, we’ve kept the default FaceColorType/EdgeColorType value of ‘truecolor’ (which is really the same as ‘truecoloralpha’ as far as I can tell, since both accept an alpha transparency value as the 4th color element). If you’re into experimentation, you might also try ‘colormapped’ and ‘texturemapped’.
p.s. – other chart types have similar internal objects that can be customized. For example, bar charts have internal Face and Edge properties that correspond to internal objects that can be similarly modified:

>> get(h.Edge)
          AlignVertexCenters: 'on'
             AmbientStrength: 0.3
                ColorBinding: 'object'
                   ColorData: [4×1 uint8]
                   ColorType: 'truecolor'
             DiffuseStrength: 0.6
            HandleVisibility: 'on'
                     HitTest: 'off'
                       Layer: 'middle'
                    LineJoin: 'miter'
                   LineStyle: 'solid'
                   LineWidth: 0.5
               NormalBinding: 'none'
                  NormalData: []
                      Parent: [1×1 Bar]
                         ...

>> get(h.Edge) AlignVertexCenters: 'on' AmbientStrength: 0.3 ColorBinding: 'object' ColorData: [4×1 uint8] ColorType: 'truecolor' DiffuseStrength: 0.6 HandleVisibility: 'on' HitTest: 'off' Layer: 'middle' LineJoin: 'miter' LineStyle: 'solid' LineWidth: 0.5 NormalBinding: 'none' NormalData: [] Parent: [1×1 Bar] ...

Related posts:

  1. Plot line transparency and color gradient – Static and interpolated (gradient) colors and transparency can be set for plot lines in HG2. ...
  2. Undocumented plot marker types – Undocumented plot marker styles can easily be accesses using a hidden plot-line property. ...
  3. Plot legend customization – Matlab plot legends and their internal components can be customized using a variety of undocumented properties that are easily accessible. ...
  4. Accessing plot brushed data – Plot data brushing can be accessed programmatically using very simple pure-Matlab code...
  5. Draggable plot data-tips – Matlab's standard plot data-tips can be customized to enable dragging, without being limitted to be adjacent to their data-point. ...
  6. Accessing hidden HG2 plot functionality – In HG2, some of the plot functionality is hidden in undocumented properties. ...
Handle graphics HG2 Hidden property Pure Matlab Undocumented feature
Print Print
« Previous
Next »
90 Responses
  1. Paul November 20, 2014 at 02:08 Reply

    Thanks, this is useful — setting an alpha component is a better way to visualise density than applying jitter.

  2. Grunde November 24, 2014 at 02:40 Reply

    Is it possible to make the area plots transparent? Or do I have to use the patch command?

    • Yair Altman November 24, 2014 at 03:02 Reply

      @Grunde – Yes this is possible, but I don’t think you need to use any undocumented features for this. Assuming you used the builtin area function to generate the plot, you can set the FaceAlpha property of the area-plot’s children.

      Alternatively, you can use the builtin alpha function.

      • Grunde November 24, 2014 at 04:16

        The area object doesn’t have any children. And the area object itself doesn’t have a FaceAlpha property. At least in 2014b.

      • Yair Altman November 24, 2014 at 04:29
        h = area(magic(4));  drawnow;  % 1x4 area object
        set([h.Face], 'ColorType', 'truecoloralpha')
        h(2).Face.ColorData(4) = 90;  % =90/255=35% opaque =65% transparent

        h = area(magic(4)); drawnow; % 1x4 area object set([h.Face], 'ColorType', 'truecoloralpha') h(2).Face.ColorData(4) = 90; % =90/255=35% opaque =65% transparent

      • Guenter December 2, 2014 at 03:59

        Dear Yair,

        For some reason on Matlab 2014b the area alpha doesn’t seem to work. I copy/paste your sample and run it. Although it doesn’t throw any error, it seems to ignore the settings in h(2).Face.ColorData(4). I can change it to whatever value, but the transparency of the faces (areas) don’t change at all.
        Am I missing something?

      • Yair Altman December 2, 2014 at 04:42

        It works for me… Perhaps you are using software emulation (not hardware acceleration) in your opengl. Type opengl(‘info’) to find out.

      • Guenter December 3, 2014 at 02:21

        Dear Yair,

        Thanks for you reply. I did some further tests and I think I found at least one problem. When I run the area command within a loop for plotting multiple sets of data into one plot it sometimes happens that the x-axis is resized to fit the data. Whenever this command is called the previous settings are discarded and all areas have the same color and no transparency. Can you confirm that using e.g.

        h = area(magic(4));  drawnow;  % 1x4 area object
        set([h.Face], 'ColorType', 'truecoloralpha')
        h(2).Face.ColorData(4) = 90;  % =90/255=35% opaque =65% transparent
        xlim([1.5 2.5])

        h = area(magic(4)); drawnow; % 1x4 area object set([h.Face], 'ColorType', 'truecoloralpha') h(2).Face.ColorData(4) = 90; % =90/255=35% opaque =65% transparent xlim([1.5 2.5])

        breaks the settings for transparency?

      • Guenter December 3, 2014 at 04:59

        Hi Again,

        So, finally I figured it out how to circumvent the problem with the resizing. I simply had to apply the color and alpha settings at the very end of my plotting script (after settings xlims, adding legends, etc.). Then this works just fine.
        Thanks again for your kind help and for putting this down for others to read!
        Cheers

  3. Michael November 25, 2014 at 10:17 Reply

    As far as I can tell, changing the EdgeColorBinding (or FaceColorBinding) from ‘object’ to ‘interpolated’ or ‘discrete’ is problematic. Entering Edit Plot mode (the pointer icon on the toolbar) resets the ColorBinding and ColorData back to ‘object’ and the original color.
    Short Example:

    x = 1:10; y= 1:10;
    pl = plot(x,y,'*');
    drawnow; % Otherwise pl.MarkerHandle gives me GraphicsPlaceholder objects
    hmarkers = pl.MarkerHandle;
    oldcolordata = hmarkers.EdgeColorData;
    newcolordata = uint8(repmat(oldcolordata,1,numel(x)));
    newcolordata(:,1) = [255;0;0;255]; % Turn the first marker red
    hmarkers.EdgeColorData = newcolordata;
    hmarkers.EdgeColorBinding = 'discrete';

    x = 1:10; y= 1:10; pl = plot(x,y,'*'); drawnow; % Otherwise pl.MarkerHandle gives me GraphicsPlaceholder objects hmarkers = pl.MarkerHandle; oldcolordata = hmarkers.EdgeColorData; newcolordata = uint8(repmat(oldcolordata,1,numel(x))); newcolordata(:,1) = [255;0;0;255]; % Turn the first marker red hmarkers.EdgeColorData = newcolordata; hmarkers.EdgeColorBinding = 'discrete';

    This will generate a simple line with the first point red. Clicking the Edit Plot icon will reset all markers.

    • Leonardo M. March 31, 2015 at 14:56 Reply

      Even without changing EdgeColorBinding/FaceColorBinding from ‘object’ to ‘interpolated’ or ‘discrete’, the original color is reset back to the original color if a legend is added to the plot:

      x=1:10; 
      y=10*x; 
      hLine=plot(x,y,'o-');
      drawnow;
      hLine.MarkerFaceColor = [0.5,0.5,0.5];
      hMarkers = hLine.MarkerHandle;                    % a matlab.graphics.primitive.world.Marker object
      hMarkers.FaceColorData = uint8(255*[1;0;0;0.3]);  % Alpha=0.3 => 70% transparent red
      legend('show');                                   % ! This will reset back the original color.

      x=1:10; y=10*x; hLine=plot(x,y,'o-'); drawnow; hLine.MarkerFaceColor = [0.5,0.5,0.5]; hMarkers = hLine.MarkerHandle; % a matlab.graphics.primitive.world.Marker object hMarkers.FaceColorData = uint8(255*[1;0;0;0.3]); % Alpha=0.3 => 70% transparent red legend('show'); % ! This will reset back the original color.

      Does anyone have a solution for this?

    • Fabian May 6, 2015 at 15:45 Reply

      Unfortunately, the same happens even when hitting ‘Edit’ -> ‘Copy Figure’ or trying to export it. I built a bunch of pretty figures with this but they are stuck within Matlab 🙁

      • Yair Altman May 6, 2015 at 16:04

        You can try to place your customization code in a short function that you’d reference in the axes CreateFcn property and/or its MarkedClean event (using addlistener).

    • Fabian May 8, 2015 at 08:32 Reply

      Yup, that works. Thanks so much, Yair. It’s a pretty awful hack job to achieve what I feel should be basic functionality but here we go:

      % generate data
      rng(144);
      xData = normrnd(1, 0.2, 1000, 1);
      yData = normrnd(1, 0.2, 1000, 1);
       
      % plot and make transparent
      ha = plot(xData, yData, 'ko');
      drawnow();
      hm = ha.MarkerHandle;
      cFace = uint8(255*[0 0 1 0.1])';
      cEdge = uint8(255*[0 0 0 0.3])';
      hm.FaceColorData = cFace;
      hm.EdgeColorData = cEdge;
       
      % keep transparent
      addlistener(ha,'MarkedClean',...
          @(ObjH, EventData) keepAlpha(ObjH, EventData, cFace, cEdge));

      % generate data rng(144); xData = normrnd(1, 0.2, 1000, 1); yData = normrnd(1, 0.2, 1000, 1); % plot and make transparent ha = plot(xData, yData, 'ko'); drawnow(); hm = ha.MarkerHandle; cFace = uint8(255*[0 0 1 0.1])'; cEdge = uint8(255*[0 0 0 0.3])'; hm.FaceColorData = cFace; hm.EdgeColorData = cEdge; % keep transparent addlistener(ha,'MarkedClean',... @(ObjH, EventData) keepAlpha(ObjH, EventData, cFace, cEdge));

      and the keep function:

      function keepAlpha(src,eventData, FaceColor, EdgeColor)  
          hm = src.MarkerHandle;
          hm.EdgeColorData = EdgeColor;
          hm.FaceColorData = FaceColor;   
      end

      function keepAlpha(src,eventData, FaceColor, EdgeColor) hm = src.MarkerHandle; hm.EdgeColorData = EdgeColor; hm.FaceColorData = FaceColor; end

      Note that when adding a legend the symbol comes up wrong. But at least I can export my scatter plots now…

  4. Claire O. February 10, 2015 at 15:52 Reply

    Thanks for all the useful tips. I have a nitpicky question: when I change any hidden property of my figures I have to manually select the line of code and execute it by itself (sometimes I have to repeat this twice before it works). It will not just execute itself if I run it as a script or a function. Any idea why that is?

    • Yair Altman February 12, 2015 at 11:56 Reply

      @Claire – it should work in a script/function as well. You are probably doing something wrong. Perhaps the figure is not visible when it reaches that line of code, or maybe you just need to add a pause(0.1) and/or drawnow before your property-modification line.

      • Claire O. March 5, 2015 at 13:15

        @Yair, I just saw your response. Thanks so much, adding the drawnow did the trick!

  5. Fabian May 5, 2015 at 08:52 Reply

    Hi.
    Thanks for writing this post. I find transparent markers really essential for making dense scatter plots readable. However, when I run your code (see below), hMarkers is empty. I use 2014b on Win8. Any idea what’s going wrong?

    x=1:10; y=10*x;
    hLine=plot(x,y,'o-');
    hMarkers = hLine.MarkerHandle;  % this is fine but returns a 0x0 empty GraphicsPlaceholder array
    hMarkers.get % hence this does nothing
    hMarkers.FaceColorData = uint8(255*[1;0;0;0.3]);  % this fails

    x=1:10; y=10*x; hLine=plot(x,y,'o-'); hMarkers = hLine.MarkerHandle; % this is fine but returns a 0x0 empty GraphicsPlaceholder array hMarkers.get % hence this does nothing hMarkers.FaceColorData = uint8(255*[1;0;0;0.3]); % this fails

    • Yair Altman May 5, 2015 at 08:56 Reply

      @Fabian – simply add a drawnow call after your plot(), before accessing hLine.MarkerHandle.

    • Fabian May 5, 2015 at 09:06 Reply

      splendid. Thank you 🙂

  6. luc May 8, 2015 at 05:37 Reply

    Hello!

    I’m trying this in matlab r2015a, I got the same problem as Fabian, but the drawnow command does not solve the problem.

    x_new3=nan; y_new3=nan; z_new3=nan;
    threednumeric3=scatter3(x_new3,y_new3,z_new3,'blue')
    set(threednumeric3,'XDataSource','x_new3');
    set(threednumeric3,'YDataSource','y_new3');
    set(threednumeric3,'ZDataSource','z_new3');
    drawnow
    hMarkers = threednumeric3.MarkerHandle;  % a matlab.graphics.primitive.world.Marker object
    hMarkers.get
    hMarkers.FaceColorData = uint8(255*[1;0;0;0.3]); % Alpha=0.3 => 70% transparent red

    x_new3=nan; y_new3=nan; z_new3=nan; threednumeric3=scatter3(x_new3,y_new3,z_new3,'blue') set(threednumeric3,'XDataSource','x_new3'); set(threednumeric3,'YDataSource','y_new3'); set(threednumeric3,'ZDataSource','z_new3'); drawnow hMarkers = threednumeric3.MarkerHandle; % a matlab.graphics.primitive.world.Marker object hMarkers.get hMarkers.FaceColorData = uint8(255*[1;0;0;0.3]); % Alpha=0.3 => 70% transparent red

  7. Philip July 16, 2015 at 08:01 Reply

    Hey Yair,

    thank you very much for these very valuable tips! They really open up a plethora of charting options that come in very handy, in my case.

    Do you have any further details / documentation about ‘MarkerHandle’? For example, I am wondering about how to use the xxBinding properties; how exactly do ‘object’, ‘interpolated’, ‘discrete’ and ‘none’ work?

    One more question: in MATLAB, I frequently need to generate a 2D scatter plot with:
    (1) use individual marker transparencies to encode a 3rd variable (e.g. age of people). Your post solves this 🙂
    (2) use individual marker sizes to encode a 4th variable (e.g. number of people). I’m stuck here: I do not know of any possibility to vary the marker sizes individually. While there are appropriate object properties (Size for the Line class, and MarkerSize for the MarkerHandle class), these are apparently required to be scalars.
    I’d love to set these to a vector. For performance reasons, I would like to avoid calling ‘line’ several times in a loop.
    Do you have any idea or suggestion?

    Thank you very much!
    Philip

    • Philip July 16, 2015 at 08:09 Reply

      an example of what I’m talking about can be found here:
      http://glowingpython.blogspot.co.at/2011/11/how-to-make-bubble-charts-with.html

    • Yair Altman July 16, 2015 at 08:15 Reply

      @Philip – If you use scatter or scatter3, then you can set the SizeData property to be either a scalar or a vector the same size as the data.

    • Philip July 16, 2015 at 23:59 Reply

      Absolutely terrific! I was not aware of SizeData…
      Thank you very much!! Hope this will help others as well.

  8. Priyanka August 7, 2015 at 05:27 Reply

    Thanks for this useful tip! I’m still finding my way around MATLAB, and unfortunately I’m stuck – was wondering if I can access the hidden MarkerHandle in Matlab 2013a? Not able to find any documentation on this. Thanks for any help.

    Cheers

    • Yair Altman August 7, 2015 at 08:37 Reply

      @Priyanka – this functionality is only available in Matlab’s new graphics system (HG2), which became officially available in Matlab release R2014b (i.e., 3 releases after yours). If you wish to access its undocumented and still unstable functionality in your R2013a, then follow the instructions here: http://undocumentedmatlab.com/blog/hg2-update#testing

  9. Dani October 2, 2015 at 03:17 Reply

    The keepAlpha of Fabian does a good job preventing Matlab to get rid of the transparency again when, e.g., legend is called. Is there a way to convince ‘legend’ to show the transparent markers properly too?

    • Christopher October 29, 2015 at 10:59 Reply

      Hi Dani and Yair,
      I have been using the keepAlpha trick with success as well to keep transparency on the figure Markers when toggling the legend. I am, as Dani, very keen to find a solution to keep the transparency in the legend markers as well.
      Any hint into where to look for a begining of solution would be very welcome. For example, is there a hidden way to access the handles to the Markers that are in the legend ? Would the optimal solution be to create a function myLegend that would design the legend from scratch ?
      BR

      • Yair Altman November 3, 2015 at 01:59

        @Dani & @Christopher:

        The legend function clears marker customizations such as transparency. You can restore the transparency by re-updating hMarkers.FaceColorData following the legend call.

        In order to customize the legend itself, we need to dig into the legend object’s hierarchy. This is not too difficult:

        hLegend = legend('on');
        hMarkers.FaceColorData = uint8(255*[1;0;0;0.3]);  % Alpha=0.3 => 70% transparent red  - restored after the legend call
        hLegendComponents = hLegend.EntryContainer.Children;  % hLegendComponents has 2 children: child 1 = LegendIcon, child 2 = Text (label)
        hLegendIconComponents = hLegendComponents.Icon.Transform.Children;  % child 1 = Marker, child 2 = LineStrip
        hLegendMarker = hLegendIconComponents.Children(1);
        hLegendMarker.FaceColorData = uint8(255*[1;0;0;0.3]);  % Alpha=0.3 => 70% transparent red

        hLegend = legend('on'); hMarkers.FaceColorData = uint8(255*[1;0;0;0.3]); % Alpha=0.3 => 70% transparent red - restored after the legend call hLegendComponents = hLegend.EntryContainer.Children; % hLegendComponents has 2 children: child 1 = LegendIcon, child 2 = Text (label) hLegendIconComponents = hLegendComponents.Icon.Transform.Children; % child 1 = Marker, child 2 = LineStrip hLegendMarker = hLegendIconComponents.Children(1); hLegendMarker.FaceColorData = uint8(255*[1;0;0;0.3]); % Alpha=0.3 => 70% transparent red

        simple.

  10. EZ November 3, 2015 at 01:10 Reply

    Hi Yair,
    Thank you for the terrific post! I have a question on printing figure to pdf (or any format really!) and retaining the transparency. It used to be that zbuffer would do the trick (loses vector format) but at least the transparency property is not lost. In >2014, zbuffer is no longer an option. I was wondering if you have had any success in using other renderers? Thanks again.
    EZ

    • Yair Altman November 3, 2015 at 02:07 Reply

      @EZ – transparency output is (and always was) problematic in Matlab. In general, painters does not render transparencies so in HG2 (R2014b onward) we need to use the slower opengl renderer for export. Try using print -dpdf and/or the export_fig utility. You’ll probably still run into limitations with either of these though.

  11. Carl Witthoft January 28, 2016 at 20:48 Reply

    (sorry about directly emailing – I missed your warnings)
    Hi – re your column on assigning transparency to plot markers: I tried the code on a simple example and all was well. Then I tried a tight loop, plotting a single point at a time (doing this to assign a different color to each point in the graph), and invariably within a few loop cycles, when I grab the “plothandle.MarkerHandle”, it’s empty. In these cases, the class of this empty object is “Matlab.graphics.GraphicsPlaceholder”
    while when the operation is successful, the class is:
    “matlab.graphics.primitive.world.Marker”

    I’ve tried things like clearing variables every loop, putting in a delay timer, and so on, with no luck. Any idea what’s going on?
    many thanks
    Carl

    • Yair Altman January 29, 2016 at 13:50 Reply

      Cross-referenced solution (as for Fabian’s issue above, to add a call to drawnow): http://stackoverflow.com/a/35070679/233829

    • Carl Witthoft January 29, 2016 at 16:58 Reply

      Yep, at least for me drawnow solved the problem. I was the OP for that SO question, btw 🙂

      • Yair Altman January 30, 2016 at 18:06

        Yes of course. But since you neglected to come back here and update that you have found a solution, causing me and other readers extra effort to look for a solution, I thought it would at least be nice of me to inform other readers here that a solution was found. Next time please be more considerate of others.

  12. ACenTe March 29, 2016 at 01:42 Reply

    Great article, it was very helpful.

    I found an issue, though I don’t think it’s related to this method “per se”. When I try to export the figure, the transparency of the markers is lost, but the transparency of other objects is kept (for example, patches).

    Is there a solution for this? or any way to export the figure exactly as it’s shown in the Figure window?

    I’m using 2014b and I’ve tried exporting to png and pdf using both the painter and the OpenGL renderers with similar results.

  13. Nasser April 17, 2016 at 03:14 Reply

    The above does not work on Matlab 2016a. I get no transparency at all.
    >> ver
    —————————————————————————————————-
    MATLAB Version: 9.0.0.341360 (R2016a)
    MATLAB License Number: STUDENT
    Operating System: Microsoft Windows 7 Home Premium Version 6.1 (Build 7601: Service Pack 1)
    Java Version: Java 1.7.0_60-b19 with Oracle Corporation Java HotSpot(TM) 64-Bit Server VM mixed mode

    x=1:10; y=10*x; hLine=plot(x,y,'o-'); drawnow;
    hLine.MarkerFaceColor = [0.5,0.5,0.5];
    hMarkers.FaceColorData = uint8(255*[1;0;0;0.3]);

    x=1:10; y=10*x; hLine=plot(x,y,'o-'); drawnow; hLine.MarkerFaceColor = [0.5,0.5,0.5]; hMarkers.FaceColorData = uint8(255*[1;0;0;0.3]);

    The dots are still the same color. No transparency. Nothing changed.

    • Yair Altman April 18, 2016 at 12:38 Reply

      @Nasser – this is because you did not read carefully, and so you missed 3 important commands!

      x=1:10; y=10*x; hLine=plot(x,y,'o-'); drawnow;
      hLine.MarkerFaceColor = [0.5,0.5,0.5];
      drawnowhMarkers = hLine.MarkerHandle;hMarkers.FaceColorType = 'truecoloralpha';hMarkers.FaceColorData = uint8(255*[1;0;0;0.3]);

      x=1:10; y=10*x; hLine=plot(x,y,'o-'); drawnow; hLine.MarkerFaceColor = [0.5,0.5,0.5]; drawnow hMarkers = hLine.MarkerHandle; hMarkers.FaceColorType = 'truecoloralpha'; hMarkers.FaceColorData = uint8(255*[1;0;0;0.3]);

  14. Lukas K. April 28, 2016 at 12:53 Reply

    Hi! I’m would like to get a better view of many points in a scatter3 plot, but unfortunately the transparency is lost once I rotate the plot. Is there a way to fix that?

    • Yair Altman May 5, 2016 at 13:49 Reply

      @Lukas – Matlab automatically removes transparency when you modify the axes (e.g., by rotation). You could attach a callback listener to the axes’ MarkedClean event that will restore the transparency once Matlab finishes doing its internal updates.

  15. Paweł July 6, 2016 at 19:44 Reply

    Hello,
    Is it possible to do with point cloud plot command: pcshow();? I want to change size of Brushing marker.
    I get this:

    >> drawnow
    >> hMarkers = hLine.MarkerHandle;
    No appropriate method, property, or field 'MarkerHandle' for class 'matlab.graphics.axis.Axes'.

    >> drawnow >> hMarkers = hLine.MarkerHandle; No appropriate method, property, or field 'MarkerHandle' for class 'matlab.graphics.axis.Axes'.

    I’ve been looking into hidden lines, axes properties, but I can’t find it anywhere.

    • Yair Altman July 6, 2016 at 20:45 Reply

      @Pawel – you have a bug in your code. As the error message indicates, hLine in your code is a handle to the axes, not to the line.

  16. Marconi Barbosa August 29, 2016 at 06:42 Reply

    Sweet. But when I try to print, Matlab2014b clears everything. I created events listeners for markers in both plot and legends. That works fine to rebuild after a click in ‘show plot tools’; but won’t work in print preview… 😐

    • Yair Altman August 29, 2016 at 10:32 Reply

      @Marconi – this has already been reported by others on this blog. Matlab’s print and saveas functions clear such transparencies, and there is no known workaround for this. You can use a screen capture utility to capture the actual appearance and then print from that screen-capture.

    • Anon October 3, 2016 at 21:54 Reply

      Use MATLAB2015b! It will print transparencies correctly.

  17. Anon October 3, 2016 at 21:52 Reply

    I found that when I upgraded to Matlab 2016a, the transparency functions will generate figures in the correct way but will not print the transparencies. Importantly, 2015b prints figures properly!

  18. LucyK October 12, 2016 at 17:15 Reply

    Thank you so much for this page, it is fantastic! I finally have my transparent scatter plots back in 2015a!

    • LucyK October 12, 2016 at 17:29 Reply

      PS I found a workaround to save transparency changes in matlab 2015a: if you use saveas to save the file as *.svg, then open in Inkscape (free) and export as a png there, transparency values are saved.

      I also found I needed to build in a brief pause in my script before obtaining the marker handle to avoid getting the following error: “Too many outputs requested. Most likely cause is missing [] around left hand side that has a comma separated list expansion.“. Reading back, it looks like another user has also mentioned this – pause(1) (shorter is possibly fine too) resolved the error.

  19. Collin November 15, 2016 at 04:33 Reply

    Hi, I was just attempting to control plot marker transparency as described in this tutorial but for a line object made using
    plot3. It seems like there is no MarkerHandle object created when using plot3. Is that the case? No way to make transparent marker faces / edges on a 3D plot?

    Thanks for making such a great resource.

    • Yair Altman November 15, 2016 at 11:12 Reply

      @Collin – there is indeed a MarkerHandle property also for plot3, exactly the same as for plot. The property is simply hidden and not displayed when you run the get/set commands, but once you know that it exists you can use it just like any other property.

    • Collin November 15, 2016 at 21:09 Reply

      @Yair – Ah, I’ve figured out my problem. Or at least I’ve figured out how to avoid it. It seems that if you set LineStyle, Marker, MarkerSize, or any items of that nature using the line handle before using hLine.MarkerHandle, then MarkerHandle becomes inaccessible.

      I’ve also noticed that none of the changes made using MarkerHandle are reflected by the line properties.

  20. John Kegelman November 18, 2016 at 09:40 Reply

    Hi all. Great post. I tried this with R2016b and ran into similar issues when trying to export, i.e. the transparency would be lost. I found that MATLAB’s scatter command does pretty much exactly what I wanted by setting the (mildly undocumented?) MarkerEdgeAlpha and MarkerFaceAlpha properties, as mentioned here. Then export_fig works its magic and everything looks great (even in pdf!). My code looked something like this:

    scatter(X, Y, 6, 'filled', ...
        'MarkerEdgeColor', [0 114 189]/255, ...
        'MarkerEdgeAlpha', 0.3            , ...
        'MarkerFaceColor', [0 114 189]/255, ...
        'MarkerFaceAlpha', 0.1);

    scatter(X, Y, 6, 'filled', ... 'MarkerEdgeColor', [0 114 189]/255, ... 'MarkerEdgeAlpha', 0.3 , ... 'MarkerFaceColor', [0 114 189]/255, ... 'MarkerFaceAlpha', 0.1);

    Hope that helps!

  21. John Smith November 22, 2016 at 02:54 Reply

    “Throughout today, we’ve kept the default FaceColorType/EdgeColorType value of ‘truecolor’ (which is really the same as ‘truecoloralpha’ as far as I can tell, since both accept an alpha transparency value as the 4th color element).”

    As far as I tested, the above is not true for R2016b. It seems that you need to set FaceColorType/EdgeColorType to ‘truecoloralpha’ in order to get transparency effect.

  22. Da V February 2, 2017 at 19:23 Reply

    Hi Yair,
    Thanks for this awesome post. I am currently using R2014b however I cannot even find the property of the marker’s handle.

    >> hLine = plot(t,x,'o','LineWidth',2); drawnow;
    >> hMarkers = hLine.MarkerHandle;
    >> hMarkers.EdgeColorData = [1,1,1,0.2];
    Invalid or deleted object.

    >> hLine = plot(t,x,'o','LineWidth',2); drawnow; >> hMarkers = hLine.MarkerHandle; >> hMarkers.EdgeColorData = [1,1,1,0.2]; Invalid or deleted object.

    My opengl setting is as follows:

    opengl('info')
                              Version: '1.1.0'
                               Vendor: 'Microsoft Corporation'
                             Renderer: 'GDI Generic'
                       MaxTextureSize: 1024
                               Visual: 'Visual 0x0e, (RGB 24 bits (8 8 8), Z ...'
                             Software: 'true'
            SupportsGraphicsSmoothing: 0
        SupportsDepthPeelTransparency: 0
           SupportsAlignVertexCenters: 0
                           Extensions: {3x1 cell}
                   MaxFrameBufferSize: 0

    opengl('info') Version: '1.1.0' Vendor: 'Microsoft Corporation' Renderer: 'GDI Generic' MaxTextureSize: 1024 Visual: 'Visual 0x0e, (RGB 24 bits (8 8 8), Z ...' Software: 'true' SupportsGraphicsSmoothing: 0 SupportsDepthPeelTransparency: 0 SupportsAlignVertexCenters: 0 Extensions: {3x1 cell} MaxFrameBufferSize: 0

    I find it very annoying that even copying some tutorial lines into my matlab doesn’t help set the target transparent.
    Do you have any suggestion for this situation? Many thanks in advance.

    Best regards,
    Da

    • Yair Altman February 2, 2017 at 19:40 Reply

      @DaV – I suspect that you have some extra code between the line where you plot() the data and the line where you extract/update the hMarkers and in the meantime either the line or the markers were deleted.

      In any case, your code was buggy in the sense that EdgeColorData expects a uint8 column array of values (as explained in my posts).

      The following code snippet should work as-is:

      hLine = plot(1:5,2:6,'o','LineWidth',2); drawnow;
      hMarkers = hLine.MarkerHandle; 
      hMarkers.EdgeColorData = uint8(255*[1,0.4,0.6,0.2]');

      hLine = plot(1:5,2:6,'o','LineWidth',2); drawnow; hMarkers = hLine.MarkerHandle; hMarkers.EdgeColorData = uint8(255*[1,0.4,0.6,0.2]');

      There is also a possibility that this does not work on R2014b, which was the first Matlab release to officially use the new graphics system (HG2). In this case, try it with a newer release if you can.

      There is also the possibility that this is due to your use of OpenGL emulation mode (software=’true’). You should really try to update your graphics driver so that Matlab will use OpenGL hardware acceleration (software=’false’), because the new graphics engine relies on OpenGL hardware much more than the previous graphics system (HG1, used until R2014a).

    • Da V February 3, 2017 at 11:31 Reply

      @Yair,

      Thanks a lot for the trouble shooting. I pasted your code into the command line, it works perfectly.
      I wondered a bit as there were actually nothing different between the code and what I tried yesterday but the last line.
      Lastly I found this would be the key:

      >> hLine = plot(1:5,2:6,'o','LineWidth',2); drawnow;
      >> hMarkers = hLine.MarkerHandle; 
      >> hMarkers.EdgeColorData = uint8(255*[1,0.4,0.6,0.2]');    %works fine
       
      >> hMarkers.EdgeColorData                                   %This cannot show the current value of the markers.
      Invalid or deleted object. 
       
      >> hMarkers.EdgeColorData.get                               %This can neither.
      Invalid or deleted object.

      >> hLine = plot(1:5,2:6,'o','LineWidth',2); drawnow; >> hMarkers = hLine.MarkerHandle; >> hMarkers.EdgeColorData = uint8(255*[1,0.4,0.6,0.2]'); %works fine >> hMarkers.EdgeColorData %This cannot show the current value of the markers. Invalid or deleted object. >> hMarkers.EdgeColorData.get %This can neither. Invalid or deleted object.

      I will try a 2016 release on another computer tomorrow. Many thanks for this post. An eye-opener 🙂

      Da

  23. KOUICHI C. NAKAMURA August 24, 2017 at 17:46 Reply

    I really liked this hidden feature, but as far as I can see, R2017a and R2017b (prerelease) do not support the alpha setting of Markers as in:

    hMarkers.FaceColorData = uint8(255*[1;0;0;0.3]);

    hMarkers.FaceColorData = uint8(255*[1;0;0;0.3]);

    The markers turn red by this, but they are not transparent.

    • Yair Altman August 25, 2017 at 14:42 Reply

      @Kouichi – I believe that you are mistaken: Depending on exactly which type of Markers you have, it is possible that you simply need to modify the EdgeColorData instead of FaceColorData, and/or to modify EdgeColorType/FaceColorType from their default value of ‘truecolor’ to ‘truecoloralpha’. You will then see the transparent markers nicely.

  24. FP October 4, 2017 at 10:34 Reply

    Is there also a hidden MarkerHandle or something similar for animatedline? Because I get the following error trying the same with animatedline:

    No appropriate method, property, or field 'MarkerHandle' for class 'matlab.graphics.animation.AnimatedLine'.

  25. Peter Rochford November 29, 2017 at 06:06 Reply

    I have written a collection of Matlab functions for creating semi-transparent markers in plots and legends. The files are available from MATLAB Central as the MarkerTransparency package. A few examples of how to use these functions are included in the download and there is also a Wiki on GitHub. A major benefit of this package is that it enables the user to have the semi-transparent markers also appear in the legend.

    • Yair Altman November 29, 2017 at 09:49 Reply

      @Peter – very nice, thanks for sharing.

      It would be nice if you would cite a reference to this page in the File Exchange description text, and in your GitHub README.md file.

  26. Hassan November 29, 2017 at 19:44 Reply

    Hi all;
    I am facing problems exporting such figures as a pdf/svg to modify it using illustrator, especially when I have multiple subplots!
    could anyone help me with this?
    Best,

    • Yair Altman November 29, 2017 at 19:47 Reply

      Try to use the export_fig utility

    • Hassan November 29, 2017 at 19:56 Reply

      the problem is once exporting either using saveas or print functions, the transparency is not saved and gives a full normal color image! Thanks.

    • Hassan November 29, 2017 at 20:12 Reply

      Thanks Yair,
      Still, have the same problem. export_fig is exporting the figure without applying the transparency to the markers. On the screen, I have a nice figure, but once exporting the figure I am loosing all. I played with the rendering options, didn’t see any change or improvement! any idea?

      • Yair Altman November 29, 2017 at 21:09

        So try using the ScreenCapture utility. Note that it only generates bitmap sceenshots, not vectorized (PDF/EPS) ones.

  27. Tyler Goodell March 1, 2018 at 00:46 Reply

    This is awesome Yair.

    However, now I’m wondering if it’s possible to change the marker of a specific subset of plotted points after they’ve already been plotted. For example, if I set x = [1:10] and y = [1:10], and I plot(x,y,’o’), is it possible to change the circles to triangles from x(2:4)?

    • Yair Altman March 2, 2018 at 11:15 Reply

      @Tyler – you cannot do that on the plotted markers directly, but you could create the line with no markers, and then overlay it with 2 additional lines that have no line, just the markers. For example:

      line(1:10,    1:10,    'LineStyle','-');  % original line with no markers
      line([1,5:9], [1,5:9], 'LineStyle','none', 'marker','o', 'MarkerFaceColor','r');  % red circle markers
      line(2:4,     2:4,     'LineStyle','none', 'marker','^', 'MarkerFaceColor','g');  % green triangle markers

      line(1:10, 1:10, 'LineStyle','-'); % original line with no markers line([1,5:9], [1,5:9], 'LineStyle','none', 'marker','o', 'MarkerFaceColor','r'); % red circle markers line(2:4, 2:4, 'LineStyle','none', 'marker','^', 'MarkerFaceColor','g'); % green triangle markers

  28. Hassan June 23, 2018 at 06:37 Reply

    Hi, I used the suggested script on pc and worked fine. However, when I moved to mac the same script stop working, and I have not transparency gradient. Any help? Thanks,

    • Yair Altman June 26, 2018 at 09:58 Reply

      @Hassan – check perhaps a different figure renderer is used on your two computers.

  29. gianfry December 9, 2018 at 14:29 Reply

    Hello, I successfully applied the transparency and color gradient to the markers. However, this works for me just with the filled (heavier) markers like ‘o’, not for the lighter markers like ‘.’ and ‘+’. Any idea on that?

    • Yair Altman December 9, 2018 at 15:45 Reply

      My hunch is that the simpler markers are implemented as OpenGL primitives and these are not painted like the more complex markers and are therefore not as customizable.

  30. Antonius Armanious March 13, 2019 at 10:29 Reply

    Thanks a lot for the very useful hack. Do you know how one can do something similar to a bar chart? In other words what would be the equivalent for MarkerHandler in a bar chart?
    Thanks a lot

    • Yair Altman March 13, 2019 at 10:47 Reply

      @Antonius – the corresponding internal objects in a bar chart are hBarChart.Edge and hBarChart.Face.

      Also see related:
      * http://undocumentedmatlab.com/blog/bar-plot-customizations
      * http://undocumentedmatlab.com/blog/customizing-histogram-plots

    • Antonius Armanious March 13, 2019 at 12:08 Reply

      I tried using hBarChart.Face to change the colors of the bars, but it did not work. I do not get any errors, but colors do not change. Here you are the command lines I used

      fbarHandle = bar( ax_fBar                                 , ...
                        Overtoone(2:6) , freqBar_AVG( 2:6 , 1 ) , ...
                        'BarWidth'     , 0.8                    , ...
                        'LineWidth'    , 0.25                   );
       
      barColor = repelem([0.5, 0.5, 0.5], 5, 1);  % all 5 bars will have the same color
      for n = 1:5
          barColor(n,4) = (6-n)*0.15;  % each bar will have a different alpha
      end
      barColor = barColor';
      barColor = barColor * 255;
      barColor = uint8(barColor);
       
      FaceHandle = get(fbarHandle.Face);
      FaceHandle.ColorBinding = 'interpolated';
      FaceHandle.ColorType    = 'truecoloralpha';
      FaceHandle.ColorData    = barColor;

      fbarHandle = bar( ax_fBar , ... Overtoone(2:6) , freqBar_AVG( 2:6 , 1 ) , ... 'BarWidth' , 0.8 , ... 'LineWidth' , 0.25 ); barColor = repelem([0.5, 0.5, 0.5], 5, 1); % all 5 bars will have the same color for n = 1:5 barColor(n,4) = (6-n)*0.15; % each bar will have a different alpha end barColor = barColor'; barColor = barColor * 255; barColor = uint8(barColor); FaceHandle = get(fbarHandle.Face); FaceHandle.ColorBinding = 'interpolated'; FaceHandle.ColorType = 'truecoloralpha'; FaceHandle.ColorData = barColor;

      • Yair Altman March 17, 2019 at 22:27

        @Antonius – try to add drawnow; pause(0.1); after the creation of the bar, before the use of the Face property.

  31. Wolfgang April 9, 2019 at 00:57 Reply

    any hint on how this works with r2018b and beyond?
    I was just trying this on a plot and get:

    h = plot(1:1:5, 'bo');
    h.FaceColorData
    No appropriate method, property, or field 'FaceColorData' for
    class 'matlab.graphics.chart.primitive.Line'.

    h = plot(1:1:5, 'bo'); h.FaceColorData No appropriate method, property, or field 'FaceColorData' for class 'matlab.graphics.chart.primitive.Line'.

    so I guess this ‘hack’ doesn’t work anymore. Is there a new way?

    • Yair Altman April 9, 2019 at 02:09 Reply

      Of course it still works. Did I ever say “h.FaceColorData” (where h is the plot return handle) anywhere in my post? Read the post text carefully and try the code snippets one by one.

    • Wolfgang May 8, 2019 at 23:40 Reply

      ok, shame on me Yair, obviously it wasn’t the plot handle, might have been too late. I had another look and of course you’re right, it works.

      Peter Rochford’s function which was an implementation of this didn’t work starting with r2018b anymore as he writes at the file exchange
      https://www.mathworks.com/matlabcentral/fileexchange/65194-peterrochford-markertransparency

      The comment of Arnold there is weird though. Adding a pause in front of setting the alpha value makes it reliable again. I wrote a test for it and yes, reliably works with a pause. Very strange.

      • Yair Altman June 16, 2019 at 18:09

        The extra pause() (or drawnow) call forces Matlab’s graphic engine to flush (execute) any pending graphic rendering events in its graphics queue, thereby ensuring that when you set the transparency it “sticks”. Without the pause/drawnow, the graphics queue might reset the transparency after you have set it, depending on internal timings over which we have no control.

        Related: http://undocumentedmatlab.com/blog/solving-a-matlab-hang-problem

  32. Hassan July 14, 2019 at 15:19 Reply

    Dear Yair,
    I have the following code that worked for me in the past. I have nothing new except or using different dataset (the Matlab version is the same 2016a). But it is not working now!
    I am getting a warning message after running the following command

    hMarkers.FaceColorData=CMdata;
    Warning: Error creating or updating Marker
     Error in value of property  ColorData
     Array contains incorrect data values

    hMarkers.FaceColorData=CMdata; Warning: Error creating or updating Marker Error in value of property ColorData Array contains incorrect data values

    Here are the full code lines that I used:

    CMtrans=uint8(255*(sum(hint.mat_norm(markersIn,:),1)./max(sum(hint.mat_norm(markersIn,:),1))));
    CMdata=uint8([repmat(mCol'*255,1,length(CMtrans)); CMtrans]);
    L2=scatter(ax,hint.xy(cellsIn,1),hint.xy(cellsIn,2),floor(ms2*frac),mCol,'filled');
    drawnow;
    hMarkers = L2.MarkerHandle;
    hMarkers.FaceColorType = 'truecoloralpha';
    hMarkers.FaceColorData=CMdata;
    set(hMarkers,'FaceColorBinding','interpolated', 'FaceColorData',CMdata);

    CMtrans=uint8(255*(sum(hint.mat_norm(markersIn,:),1)./max(sum(hint.mat_norm(markersIn,:),1)))); CMdata=uint8([repmat(mCol'*255,1,length(CMtrans)); CMtrans]); L2=scatter(ax,hint.xy(cellsIn,1),hint.xy(cellsIn,2),floor(ms2*frac),mCol,'filled'); drawnow; hMarkers = L2.MarkerHandle; hMarkers.FaceColorType = 'truecoloralpha'; hMarkers.FaceColorData=CMdata; set(hMarkers,'FaceColorBinding','interpolated', 'FaceColorData',CMdata);

    Any advice?
    Thanks, HM

    • Hassan July 14, 2019 at 18:44 Reply

      solved. the scatter plot was prepared for part of the full cell number!

  33. Tim December 21, 2019 at 00:56 Reply

    Thank you for this post, it is very useful. It seems that when using plot3, if I have more than 25,000 points and I change my figure size or rotate the image, the MarkerHandle values revert back to the original settings and all color-information and/or transparency information is immediately reset. It is simple enough to reset the MarkerHandle properties following a viewpoint transformation but it is a bit of a pain, especially since I would like to explore the 3D point cloud using zoom and rotation. Have you discovered a similar issue and is there a workaround to this problem? The Matlab version I’m using is R2019a

  34. Pierre August 26, 2020 at 12:15 Reply

    Hello,
    This post has been really useful to me. I just want to share a small trick. I have no idea whether it is reproducible or how it works, but it does the job for me (Win 10, R2019b).
    When I use plot function, the transparency settings are always reset by any command related to the current figure.
    However, when I use errorbar the transparency settings are kept. So, I have been using errorbar instead of plot, with a ‘fake’ error vector, and a capsize equal to 0.
    E.g.:

    fake_y_error = zeros(length(data_y),1);
    he = errorbar(x_data, y_data, fake_y_error)
    drawnow
    he_mh = he.MarkerHandle;
    he_mh.FaceColorType = 'truecoloralpha';
    he_mh.FaceColorData = uint8(255*[1;0;0;0.3]); 
    he.CapSize = 0;

    fake_y_error = zeros(length(data_y),1); he = errorbar(x_data, y_data, fake_y_error) drawnow he_mh = he.MarkerHandle; he_mh.FaceColorType = 'truecoloralpha'; he_mh.FaceColorData = uint8(255*[1;0;0;0.3]); he.CapSize = 0;

    And, all the more convenient, it works when actual error-bars are needed.

    • Yair Altman August 26, 2020 at 12:27 Reply

      @Pierre – thanks for sharing this clever useful trick

  35. Oliver March 7, 2022 at 20:33 Reply

    This seems to have been disabled in the most recent version of Matlab (R2021b). When I use this method the hMarker.FaceColorData does change, but the markers are not made transparent. Any ideas?

    • Yair Altman March 7, 2022 at 20:47 Reply

      Oliver – you probably forgot to update hMarkers.FaceColorType to ‘truecoloralpha‘:

      x=1:10; y=10*x;
      figure; hLine = plot(x,y,'o-');
      hLine.MarkerFaceColor = 'r'; drawnow
      hLine.MarkerHandle.FaceColorType = 'truecoloralpha';  % default='truecolor' without alphahLine.MarkerHandle.FaceColorData = uint8(255*[1;0;0;.3]);
      drawnow

      x=1:10; y=10*x; figure; hLine = plot(x,y,'o-'); hLine.MarkerFaceColor = 'r'; drawnow hLine.MarkerHandle.FaceColorType = 'truecoloralpha'; % default='truecolor' without alpha hLine.MarkerHandle.FaceColorData = uint8(255*[1;0;0;.3]); drawnow

      • Dom May 30, 2022 at 19:49

        Yair I have tried your code with trucoloralpha and the markers do not appear transparent in R2021b, same as for Oliver.

      • Yair Altman May 31, 2022 at 18:30

        Dom – call drawnow *just before* you set hLine.MarkerHandle.FaceColorType to 'truecoloralpha'.
        Also, you made a typo in your code: it’s truecoloralpha, not trucoloralpha.

Leave a Reply
HTML tags such as <b> or <i> are accepted.
Wrap code fragments inside <pre lang="matlab"> tags, like this:
<pre lang="matlab">
a = magic(3);
disp(sum(a))
</pre>
I reserve the right to edit/delete comments (read the site policies).
Not all comments will be answered. You can always email me (altmany at gmail) for private consulting.

Click here to cancel reply.

Useful links
  •  Email Yair Altman
  •  Subscribe to new posts (feed)
  •  Subscribe to new posts (reader)
  •  Subscribe to comments (feed)
 
Accelerating MATLAB Performance book
Recent Posts

Speeding-up builtin Matlab functions – part 3

Improving graphics interactivity

Interesting Matlab puzzle – analysis

Interesting Matlab puzzle

Undocumented plot marker types

Matlab toolstrip – part 9 (popup figures)

Matlab toolstrip – part 8 (galleries)

Matlab toolstrip – part 7 (selection controls)

Matlab toolstrip – part 6 (complex controls)

Matlab toolstrip – part 5 (icons)

Matlab toolstrip – part 4 (control customization)

Reverting axes controls in figure toolbar

Matlab toolstrip – part 3 (basic customization)

Matlab toolstrip – part 2 (ToolGroup App)

Matlab toolstrip – part 1

Categories
  • Desktop (45)
  • Figure window (59)
  • Guest bloggers (65)
  • GUI (165)
  • Handle graphics (84)
  • Hidden property (42)
  • Icons (15)
  • Java (174)
  • Listeners (22)
  • Memory (16)
  • Mex (13)
  • Presumed future risk (394)
    • High risk of breaking in future versions (100)
    • Low risk of breaking in future versions (160)
    • Medium risk of breaking in future versions (136)
  • Public presentation (6)
  • Semi-documented feature (10)
  • Semi-documented function (35)
  • Stock Matlab function (140)
  • Toolbox (10)
  • UI controls (52)
  • Uncategorized (13)
  • Undocumented feature (217)
  • Undocumented function (37)
Tags
AppDesigner (9) Callbacks (31) Compiler (10) Desktop (38) Donn Shull (10) Editor (8) Figure (19) FindJObj (27) GUI (141) GUIDE (8) Handle graphics (78) HG2 (34) Hidden property (51) HTML (26) Icons (9) Internal component (39) Java (178) JavaFrame (20) JIDE (19) JMI (8) Listener (17) Malcolm Lidierth (8) MCOS (11) Memory (13) Menubar (9) Mex (14) Optical illusion (11) Performance (78) Profiler (9) Pure Matlab (187) schema (7) schema.class (8) schema.prop (18) Semi-documented feature (6) Semi-documented function (33) Toolbar (14) Toolstrip (13) uicontrol (37) uifigure (8) UIInspect (12) uitable (6) uitools (20) Undocumented feature (187) Undocumented function (37) Undocumented property (20)
Recent Comments
Contact us
Captcha image for Custom Contact Forms plugin. You must type the numbers shown in the image
Undocumented Matlab © 2009 - Yair Altman
This website and Octahedron Ltd. are not affiliated with The MathWorks Inc.; MATLAB® is a registered trademark of The MathWorks Inc.
Scroll to top