MATLAB: Bug in plot function - matlab

I wrote some code at home to plot some 3D-data. It worked fine. Now I ran the same code at the office and I got some weird bug. It seems that there is a label for each data point inserted.
But this only happens on half of the plots. The left plot shows the real data and the right one is just a smoothed fit of this data. The left one gets the error and the right one doesn't.
I ran the code on the machine of a colleague and it worked fine too. So I saved the clean figure files on his machine and tried to open them on my PC. Still the same bug. So it's not the code but seems to be some weird displaying bug.
Did anyone see this before?
figure(1);
s1=gca;
surf(t_matrix,f_matrix,alpha_matrix)
colorbar
figure(2);
s2=gca;
surf(t_matrix2,f_matrix2,alpha_matrix2)
colorbar
It's just this code. And if I debug, the numbers appear after the first call to colorbar. But not in the second case. My Matlab version at home is 2013a, but at the office and that from my colleague are both 2012b.

This seems to be a bug. There is a thread on MATLAB Answers.
The accepted answer there by Jan Simon is
This could be cause by the OpenGL driver. Did you install the newest
drivers of your graphics cards?
Workaround might be:
set(gcf, 'renderer', 'zbuffer');
or if OpenGL looks nicer:
opengl software
or perhaps:
opengl hardware
Look for "OpenGL" in the documentation to find a bunch of switches to
consider a bunch of driver bugs.

Actually the zbuffer renderer works fine but is not enough in some cases.
I often use to work with transparent surface plot using the gca property facealpha set to 0.5 in order to superpose a contour plot to it. Face or edge alpha settings (maybe some other plot properties) are only correctly displayed with the Opengl renderer. The zbuffer cannot picture transparent surface plot.
The main issue first came to my attention when I recently switched to Win8. Bloody $Bill 'HamsterWhy' Gate.
A patch from Mathworks would be greatly appreciated.

Related

Make grid visible with imagesc (Linux software opengl)

I'm talking about the grid() command, not the previously asked and answered questions about showing lines around pixels (data cells). My image is of scientific data that has relevant axes and I would like the grid to overlay on the image plot. When I call grid(), the grid is there, but imagesc() covers it up. I can see it if I change the alpha of the image, but then the image looks grayed out. Is there another option?
EDIT: Here's an example of what I want. It turns out that it works just fine on my Windows machine, but my linux box shows no grid lines as described above. The linux machine uses software opengl. Any workarounds?

How to visualize 3D volume?

I had tried the following demo code in Matlab. I'm using Matlab 2018b
load('spiralVol.mat');
h = volshow(spiralVol);
But I'm getting a black screen.imshow() is working properly. Is it related to opengl? i tried opengl software and opengl hardware
Is it a bug in matlab 2018b? or is it related to my system configuration
The black screen is sometimes an issue due to bad graphics driver. Try updating the driver to its latest version.
Alternately, Image Processing Toolbox has a 'VolumeViewerUseHardware' preference setting which tells it not to use the graphics card while rendering. Try setting it to false and see if it resolves the issue:
iptsetpref

GUI Layout Toolbox - Strange display with card panel object

Context
Using the GUI Layout toolbox I have created an interface which basically is divided in two parts:
A toolbar area where the user selects the way he want to see data
A preview area to display data upon selected mode in the toolbar
For the preview area I used a uietxras.CardPanel object to switch between the view modes.
Problem
After some investigations, I discovered that if I display things in 3D (or 2D) in one of the preview card using surf (or pcolor) then it alters the display in the second card. If I display data in 1D only using plot commands I have not issue!
The issue I have when using pcolor/surf in one of the preview card:
Titles and labels seem to overlay in Preview 1
Axis borders are not displayed correctly in preview 2
Legend borders (when displayed) are altered also
If I only use plot commands in both preview modes I have no issue at all and cards are switching nicely.
Test case
My real code is really long, I have thus reduced it to the minimum so you can reproduce the issue:
https://gist.github.com/CitizenInsane/54f3c1eba2293d0e5264#file-guilayoutbug-m
Simply run the code and check the checkbox "Do 3D plot in preview 1" to see the issue happening when switching between the two preview modes:
Notes
As far I know, I'm using latest version of the GUI Layout toolbox (1.17).
I'm using R2013b for Matlab
I came across this issue as well. I'm afraid I never quite worked out what the cause was exactly, and it didn't appear in a very consistent way. The issue seems to be that plots on non-selected cards are not hidden properly, and get overlaid just behind and around the edges of the plots on the selected card.
I would encourage you to raise the issue with the authors of GUI Layout Toolbox via the comments on the toolbox's page at MATLAB Central, as I do think it's a bug.
Nevertheless, the reason I never followed it up myself is that I found a fairly straightforward workaround, which may also work for you. Each time the selected card is changed, I ran a simple function that deleted all children of all cards, and then re-plotted whatever I wanted on the selected card. It seemed a bit annoying to have to do that, but it worked, and removed any of the display issues you've come across.
Ok got it, the issue has nothing to do with CardPanel themselves, it is linked to the renderer of the figure.
Trying simple code below:
figure(42);
subplot(1,2,1);
plot(rand(1,12));
subplot(1,2,2);
peaks;
shading flat;
If the figure's renderer is set to 'OpenGL' (the default) ==> there are some glitches:
If the figure's renderer is set to 'zbuffer' ==> there is no glitch:
Setting the renderer to 'zbuffer' fixes the problem.
NB: Maybe OpenGL rendering can be fixed by fine tuning graphic card acceleration settings, but I don't know ... I issued opengl software and opengl hardware commands in Matlab and software rendering is worst than hardware rendering on my machine.
EDIT: Side notes
Transparency effects are only available if the renderer is set to 'openGL'. It is thus not possible to visualize at the same time both 1D and transparent-3D data without glitches (at least with hg version 1 in R2013b).
HG2 has no issue:

How to create article-quality 3-D plots?

Lately I've been working on how to make my MATLAB figures article-quality, since normal output plots don't look that nice. The function export_fig from the File Exchange has done a lot of pretty things for me, but now I've come to a new challenge: making a high-quality 3-D plot.
I figured the best place to start looking is here, so my question is: how to make a good-looking 3-D plot using only MATLAB? And don't get me wrong, I know how to make a 3D plot, I just want my figures to be looking article-quality!
Any suggestions?
If you are satisfied with the figure's quality on screen, you can just save the figure in .eps fully-vectorized format. Then open it - on OSX I use the standard preview software - and save it as a light .jpg for the initial submission, and as .tiff, png or pdf depending on the journal requirements. preview can export an .eps at 600/1200 pixels per inch, compressed or not, and cropping is easily done with a mouse. A minor point: vectorized exported figures do not render unfamiliar fonts.
Here is an example from matlab, exported as .eps and saved as .png 400 ppi.
try enabling handle graphics 2 if you are on one of the later versions of Matlab. Use
-hgVersion 2 startup switch in your Matlab command-line.

Sample Tutorials Of Plotting A 2D Graph On Phone SDK

Can someone give me some good tutorials on Creating a 2D plot on IPhone given a variable number of x,y coordinates?
If you're looking for something beyond just plotting the points, check out the open source Core Plot framework for Mac and iPhone. It's still a young project, but it can handle a scatter plot (with or without lines between the points) along with labeled axes just fine. There are a number of example programs included with the framework that demonstrate some of its capabilities.
You can do this with the CGContextAddLineToPoint method.
http://developer.apple.com/iphone/library/documentation/GraphicsImaging/Conceptual/drawingwithquartz2d/dq_paths/dq_paths.html#//apple_ref/doc/uid/TP30001066-CH211