Fill, Alpha, Datenum: what is the problem?

1 view (last 30 days)
Good morning, I am trying to plot a transparent box in a plot where the X-axis is time. I have problems when I enable the "Alpha" flag, check the piece of code I attach here. Any suggestion about a possible workaround? The problem appears only when I use timestamp, otherwise it is ok. Thanks in advance! Best regards Davide
x1 = '20-May-2015 07:28:06';
x2 = '20-May-2015 07:38:06';
x3 = '20-May-2015 07:00:00';
x4 = '20-May-2015 08:00:00';
figure();
fill([datenum(x1),datenum(x2),datenum(x2),datenum(x1)],...
0.0,0.0,5.0,5.0],1-0.3*(1-[1 0 0]),'FaceAlpha',0.5);
grid on;
hold on;
plot([datenum(x3) datenum(x4)],[0.0 .5],'.-r','MarkerSize',12,'Linewidth',2.0);
datetick('x',15,'keepticks');
axis([datenum(x3) datenum(x4) -2.0 +7.0]);

Accepted Answer

Walter Roberson
Walter Roberson on 20 May 2015
When you use FaceAlpha, that forces the use of the OpenGL renderer. Without it, you are getting the Painters renderer. OpenGL can have difficulty when the axis values are very close together.
If you do not need to use a DataCursor, the workaround is to shift and scale the values you use for the X axis so that they are numerically further apart, then set the XTick according to the shifted and scaled values, and then set the XTickLabel property according to what you would want the user to see at those locations. For example you might datevec() to extract the hours, minutes, seconds for the places you would like ticks, and sprintf() the parts together to get a tick label.
  1 Comment
Davide Luigi Perego
Davide Luigi Perego on 20 May 2015
Hi Walter, thanks for your quick reply. Unfortunately it is not completely clear. Is it not possible to set the Painters rendere instead? I copy below the specs of my openGL rendere. Thanks Davide
>> opengl info
Version = 4.2.12352 Compatibility Profile Context 13.101.1.0
Vendor = ATI Technologies Inc.
Renderer = AMD Radeon HD 8750M
MaxTextureSize = 16384
Visual = 02 (RGB 32 bits(08 08 08 08) zdepth 24, Hardware Accelerated, Opengl, Double Buffered, Window)
Software = false
  1. of Extensions = 241
Driver Bug Workarounds:
OpenGLBitmapZbufferBug = 0
OpenGLWobbleTesselatorBug = 0
OpenGLLineSmoothingBug = 0
OpenGLDockingBug = 0
OpenGLClippedImageBug = 0
OpenGLEraseModeBug = 0

Sign in to comment.

More Answers (0)

Categories

Find more on Graphics Performance in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!