Use "windows(width=x,height=y)" function with built-in graphic device in StatEt? - eclipse

I'm working with StatEt in Eclipse. The built-in
graphic device of StatEt generally works very well
and is of big use (big thanks to the developpers).
But when I start a plot with the windows() function
to set the size (width & height) of the new window,
this window will be opened by R outside StatEt &
R crashes.
Anybody an idea what the problem could be?

Problem solved: Use dev.new() instead of windows() !

Related

Greek letter \xi issue in Matlab eps print out

When I plot a figure and type greek letter in the title, it looks like
However, when I save the figure as EPS output, the eps file looks like
It's obviously that the Greek letter \xi_p disappears.
Anyone who knows what happened and solutions, please give me a reply.
It would be much grateful.
Best regards,
mike
First I would like to thank KiW for the help.
I found a solution that works with my MATLAB 2014b.
Solution by specifying the interpreter directly in the code
We can set the interpreter-property directly to latex when calling xlabel or title as shamalaima pointed out in a comment:
xlabel('$\xi_{\textrm{p}}$','Interpreter','latex');
title('$\xi_{\textrm{p}}$','Interpreter','latex');
Solution using the property editor
Another way to do it is by using the property editor as follows:
After making the figure, click the white arrow and click the title (or label).
In the Property Editor, change the Interpreter to latex.
After this, choose the Axes. We can now find the title editor in the left bottom side. Just write the title as you do in latex.
Mine would be $\xi_{_\textrm{p}}=1e$-$4a_{_\textrm{ho}}$ in the font of Times New Roman.
It works now in my EPS output.
Using EPS Viewer the symbol is not lost. As you can see in the picture that works perfectly fine. I used:
plot(x,y)
title('\xi _{P}=1e-4a _{ho}')
So I assume it could be a problem of the program you use to open your .EPS file
I think that the best solution is to set the latex interpreter as default:
set(0,'defaulttextinterpreter','latex')
but of course it depends case by case.

Create shape mask for GTK Window?

I am interested if anyone has any experience with the following function of the gtk.Window/gtk.Widget
shape_combine_mask(shape_mask, offset_x, offset_y)
I want to make the window round rather than rectangular. How do I get a shape_mask? It says that it has to be a bitmap. Should I use gtk.Pixbuf to get bitmap from an image? Or should I use cairo to get a shape with cairo_region_create_from_surface and then use another function that accepts the gtk.Region as a first argument?
It would be pretty rad if someone could post an example for this, C/C++ or preferably Python.
I use GTK version 2
Thank you in advance!
The answer to my question was provided by comment to the question and was implemented the same year in Python 2, using PyGTK and Cairo.
If anyone is interested on how to do this, you can see the working example here: https://github.com/stamat/droplets/blob/16b11c4ff96cf0b8e4fcdd85ee1cdc1fa8fb74e6/droplets/droplet.py#L127
Happy window shaping! 🪟🧩✨

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.

emacs windows, distribute the width through the frame

I used once a very nice emacs function that set all my windows (emacs windows, not frames) width evenly.
If you open emacs and do C-x 3 twice in a row, you get three vertical windows. Then running the function I am looking for makes the width of these windows the same.
I can't for the life of me find this function again.
Wouldn't someone help me to:
find the name of the function
give me the keyboard shortcut if any
tell me what I should have done to find the answer by myself
Thanks!
You're looking for M-x balance-windows.

Get dpi settings via GTK

Using GTK, how do I query the current screen's dpi settings?
The current accepted answer is for PHPGTK, which feels a bit odd to me. The pure GDK library has this call: gdk_screen_get_resolution(), which sounds like a better match. Haven't worked with it myself, don't know if it's generally reliable.
The resolution height and width returned by screen includes the full multi-monitor sizes (e.g. combined width and length of the displayer buffer used to render multi-monitor setup). I've not check of the mm (millimeter width/height) calls returns the actual physical sizes but if it report combined physical sizes then the dpi computed from dividing one with another would be meaningless, e.g. to draw a box on screen that can be measured using a physical ruler.
See GdkScreen. You should be able to compute it using the get_height and get_height_mm or with get_width and get_width_mm.