Matlab figure window is not showing up - matlab

I cannot open a figure window in freshly installed Matlab 2015b on a new PC. It draws correctly in taskbar small preview windows, but when I am trying to open the figure window - nothing happens. Also, saving a figure to PNG file works normally. This applies to figure windows that are empty or have something plotted (by plot, hist, etc.) except if something is drawn with imshow - in this case figure behaves normally (at least it looks so).
I tried set(gcf, 'Renderer', 'zbuffer') but nothing changed.
PC specs:
Windows 7 x64
Gigabyte GeForce GTX 980Ti G1 Gaming with version 355.98 Driver
Double Xeon CPUs

Related

Why does my figure appear to be animated (when it shouldn't be)?

Consider the following code which draws a figure:
figure('Renderer', 'opengl');
N = 50;
tL = linspace(0.5, 6, N).';
tB = sort(randi(100,N,20),1);
yyaxis right; plot(tL, tB);
xlim([2 6]);
When I run this code, I get a haunted figure with moving lines that should be static, for example (this one is using my real data which looks a bit nicer than the example):
Several additional observations:
I noticed that without the xlim line nothing happens (i.e. the figure is static as expected).
I couldn't get it to work on another computer running the same MATLAB version.
The line "animation" seems to coincide with the appearing and disappearing of the axes' toolbar (the one on the top right with the zoom etc.).
When I create the figure using figure('Renderer', 'painters') this doesn't happen.
Can somebody please explain why this is happening? Is this documented behavior? Any idea how to control it?
I'm working with R2018b on Windows 10 v1803. My screens are connected to the on-board GPU which is Intel HD Graphics 530 (driver version 22.20.16.4749).
September 2019 Update: This also happens for me on R2019b on Windows 10 v1903. As suggested in the comments, below is the output of opengl info:
Version: '4.5.0 - Build 25.20.100.6373'
Vendor: 'Intel'
Renderer: 'Intel(R) HD Graphics 530'
RendererDriverVersion: '25.20.100.6373'
RendererDriverReleaseDate: '18-Nov-2018'
MaxTextureSize: 16384
Visual: 'Visual 0x07, (RGBA 32 bits (8 8 8 8), Z depth 16 bits, Hardware acceleration, Double buffer, Antialias 8 samples)'
Software: 'false'
HardwareSupportLevel: 'full'
SupportsGraphicsSmoothing: 1
SupportsDepthPeelTransparency: 1
SupportsAlignVertexCenters: 1
Extensions: {223×1 cell}
MaxFrameBufferSize: 16384
Firstly, you should understand that a figure is not a static picture
at all. It refreshes frequenctly. If one resize/move the
container(figure), the figure will be redrawed just after the
interaction.
Secondly, All objects,including lines,annotations,legend... , are
redrawed at the same time. The discontinuous line types will be
captured easily. This why you could see a "animated" dashed line.
Lastly, for matlab, there are some interaction differences on
Linux/Mac and Windows. On Windows, Move Mouse on figure will not fire
data tracking event. But on Linux, the Data Tracker will be activated
on Mouse move. Events for data tracking, object selection etc will
refresh the plot.
All in all, the "animation" you see is designed by the author, and it should be.
The following code disabled the current axes's hit test visibility, so the redraw event won't be fired during mouse move or click on axes. But with the resize event, all objects must be redraw (which is a intentionally designed behaviour).
figure('Renderer', 'opengl');
N = 50;
tL = linspace(0.5, 6, N).';
tB = sort(randi(100,N,20),1);
yyaxis right; h = plot(tL, tB,'ButtonDownFcn',#lineCallback);
set(gca,'HitTest','off')
xlim([2 6]);
function lineCallback(Figure1,Structure1)
disp('Button Down: redraw...');
end
This code snippet has been tested using MATLAB R2018B on Mac,window10 and Ubuntu 18.04. All works fines.

MATLAB R2016b rendering trouble: line color with shades where it should not

In MATLAB R2016b I have trouble with rendering.
1) When hardware acceleration is enabled (default, or setting opengl hardware) I get:
=> when lines are close one to each other lines are darker and ligher when isolated. I want constant color.
2) When acceleration is done with software (opengl software) I get:
=> lines are always at same dark level (what I want)
Note: with the process of putting the images on the site, what I want to show is less clear but I hope still visible and understandable...
Question: is there a way to enable GPU acceleration (opengl hardware) while also having a consistent rendering of line color along the whole line?
When hardware acceleration is 'on' [1], the GraphicsSmoothing property of figures is 'on' by default, and the AlignVertexCenters property of lines if 'off' by default. This gives the result of Figure 1 in the question.
Switching AlignVertexCenters to 'on' solves the issue (the same as when turning off hardware acceleration, as stated) and gives the Figure 2.
Now, to set this permanently, add this into startup.m (the file launched by MATLAB at each startup if found in userpath)
set(0, 'DefaultLineAlignVertexCenters', 'on')
For more information of startup.m see https://mathworks.com/help/matlab/ref/startup.html
[1] this is the default if an up to date graphics card is installed, and can be checked typing opengl info and verifying that HardwareSupportLevel=='full' for example.

Saving Matlab/Octave plots to pdf/png format from online IDE?

I'm currently using the Matlab/Octave online IDE at http://www.tutorialspoint.com/execute_matlab_online.php and I'm trying to save a graph that I'm plotting to .pdf format. I've done the following:
- octave
- x = [ 1: 10 ]
- y = x
- plot(x,y)
- print -dpdf graph.pdf
I then refresh the the files and folders to the left, double click on the graph.pdf file and am always greeted with a black filled rectangle. I've then attempted to run the following:
- axis("off")
- print -dpdf graph2.pdf
And the graph appears to save to pdf correctly. However, without the axes. Could you please assist me in finding a solution?
P.S. I have already attempted octave --force-gui and graphics_toolkit('gnu_toolkit')/graphics_toolkit('fltk') with no luck.
At the site hosted, the only graphics toolkit available is gnuplot, which support in octave was mostly dropped several versions ago.
gnuplot has the bug you've described. In the link, people got plotting working by rolling back to previous gnuplot versions.
Guess the only way of getting printing working on the site would be signalling about the issue to its administration.
Also, note that octave crudely depicts the copy of the plot in terminal window. That might suffice for correctness check of the plotting code itself.
Alternatively, you can save octave graphics objects with hgsave command, those then can be loaded in octave on another computer to obtain same plot as one that would be drawn there. (Although, at this point there might be no reason for using online interpreter then.)

How to get screen resolution in pixels in Octave?

How do I get current screen (display) resolution in Octave?
Equivalent to Matlab's:
get(groot, 'ScreenSize')
UPD.
The final octave script should run on windows & mac, Octave 4.0
It's as simple as:
get(0, 'screensize')
See Introduction to Graphics Structures

How to export non-blurry eps images?

I'm exporting an image in Matlab using the eps format, but it smooths the image. Matlab does not blur the image using other formats such as png. I would like to know how to export a non-blurry image with eps format. Here is the resulting image using png:
And here is the resulting image using eps:
UPDATE:
The problem is reproducible on a Mac, and the issue is with the eps renderer rather than MATLAB. For e.g., saving imagesc(rand(20)) and viewing with Preview and GSview results in the following:
Preview screenshot
GSview screenshot
Clearly, the information is not lost. It is just not interpreted/read correctly by some EPS viewers. The solution is simple: use GSview to view your eps images. You can download it from here
On Macs especially, if your end application is latex/pdflatex, you will have to explicitly set it to use GS/GSview, because otherwise, it will default to the Quartz engine, which is baked into the OS.
PREVIOUS ANSWER:
I am unable to reproduce the behavior your described. Here is the code I used, tested using R2010b on WinXP 32-bit:
M = fspecial('gaussian',[20 20],5);
imagesc(M)
print('-dpng','a.png')
print('-depsc2','b.eps')
a.png
b.eps
Perhaps this is an issue with your EPS viewer...
not sure why it works but you can try doing the following:
eps2eps oldfile newfile
does the trick for me (on a mac os)
At first I thought you were doing something incorrectly, but then I remembered that this was an issue that was bothering the hell out of me a year or so ago. I couldn't come up with a way to "fix" this behaviour and from what I've researched, this is most likely a bug and several others have had this problem too and there is no known solution. Of course, I could be wrong about the last part and there might be solutions out there that have come out since I looked for them.
Any way, my workaround this problem was to use pcolor with shading flat instead of imagesc. When you export this to an eps format it preserves the image correctly. Example:
pcolor(rand(20));
shading flat
print('-depsc','figure.eps')
NOTE: You might see the appearance of thin, faint white lines along the anti-diagonals of each little square (depends on the OS & viewer). These are the edges of the graphics primitives that are used to render the image. However, this is not a flaw in MATLAB's export, but rather a fault in rendering in your EPS/PDF viewer. For e.g., with the default settings in Preview on my mac, these lines show up, whereas with the default in Adobe Reader 9.4, they don't appear.
If anyone is still interested in a workaround: Open the .eps-file with text editor and search for "interpolate". You'll probably find "/Interpolate true def" two or three times. Replace "true" with "false" and be happy :)
A note regarding Yoda's answer: in Preview in Mac OS X, you can make the thin white diagonal lines across each of the squares disappear by unchecking "Anti-alias text and screen art". Of course, the downside is that then any text (e.g. figure axes, etc) is not anti-aliased. Unfortunately, unchecking that has no effect on blurriness if you're using imagesc.
Another note is that if you use preview to make a pdf from your eps, the resulting pdf still displays correctly (non-blurry) when you open it in Acrobat.
I've been long struggling with this problem as well. So far, GSView is the only viewer I've found that displays the eps figures produced by Matlab (R2015b) correctly. eps2eps did not work for me (psutils 1.23).
The following eventually worked for me:
Export the figure to pdf, following the instructions here
pdf2ps file.pdf file.eps
I just wrote this simple drop-in replacement for imagesc. It doesn't support all but the most basic features, but I still hope it helps.
function h = imagesc4pdf(C)
[ny nx] = size(C);
px = bsxfun(#plus, [-0.5; 0.5; 0.5; -0.5], reshape(1:nx, [1 1 nx]));
py = bsxfun(#plus, [-0.5; -0.5; 0.5; 0.5], 1:ny);
n = numel(C);
px = reshape(repmat(px, [1 ny 1]), 4, n);
py = reshape(repmat(py, [1 1 nx]), 4, n);
h = patch(px, py, reshape(C,1,n), 'linestyle', 'none');
xlim([.5 nx+.5]);
ylim([.5 ny+.5]);
set(gca, 'ydir', 'reverse');
Apply opengl renderer to the figure
figure(gcf);
set(gcf,'renderer','opengl');
The blurring actually depends on the rendering software your viewer application or printer uses. To get good results all the time, make each pixel in your image an 8x8 block of pixels of the same color, i.e. resize the image like this:
im2 = imresize(im1, 8, 'nearest');
The blurring then only affects the pixels at the edge of each block. 8x8 blocks are best as they compress without nasty artifacts using DCT compression (sometimes used in eps files).
This page helped me a lot: http://tech.mof-mof.co.jp/blog/machine-learning-octave.html (written in Japanese, please use google translate for it)
And this is also helpful: Octave-Gnuplot-AquaTerm error: set terminal aqua enhanced title "Figure 1"...unknown terminal type"
I also answered at https://www.coursera.org/learn/machine-learning/discussions/weeks/2/threads/Dh-aRfqSEeaHSQ6l4xnh6g.
I reinstalled gnuplot like this:
$ brew cask install xquartz
$ brew cask install aquaterm
$ brew uninstall gnuplot
$ brew install gnuplot --with-aquaterm --with-x11 --with-qt # you can show other options by `$ brew options gnuplot`
You may edit ~/.octaverc like this:
setenv("GNUTERM", "qt")
and in octave window, after typing "system gnuplot", then
set pm3d interpolate 2, 2
After saving the file, open octave-cli.app, and type
imagesc(magic(3)), colorbar
I got this.