In Octave there is the problem that with fltk and qt greek letters in figures are not printed, only with gnuplot as graphics_toolkit. But then with gnuplot all lines are solid, no dashed lines.
I found a page which says that other linestyles can be enabled:
http://wiki.octave.org/Enable_%22linestyle%22_functionality_for_Gnuplot%27s_x11_terminal
I added the lines there to my ~/.Xdefaults and did xrdb -merge .Xdefaults as said there,
but no success.
I am running octave 4.0.2 on Ubuntu 16.04.
Any hints?
Thanks
Karl
It seems you cannot do it for the time being. But if you're happy for workarounds, your best choice seems to be to create an image of greek text and use that as your title etc.
Here's a way. Go to the codecogs online latex editor and write your greek title using their tool in tedious math mode :p If you copy the link to the resulting image, you can use that straight into imread if you prefer to saving a file (this also makes your code automatic such that it can be used in a script, assuming you have an internet connection.
e.g. I used the following math tex to generate the greek title:
\Pi\acute\alpha\lambda\iota~\sigma\kappa\alpha\tau\acute\alpha~\tau\alpha~\kappa\acute\alpha\nu\alpha\mu\epsilon~\mu\epsilon~\tau\alpha~E\lambda\lambda\eta\nu\iota\kappa\acute\alpha~\rho\epsilon~\mu\alpha\lambda\acute\alpha\kappa\epsilon\varsigma
and then using the link to the resulting image (or saving locally)
>> image % draw octave logo
>> greektitle = imread('http://latex.codecogs.com/png.latex?%5Cdpi%7B300%7D%20%5Chuge%20%5CPi%5Cacute%5Calpha%5Clambda%5Ciota%7E%5Csigma%5Ckappa%5Calpha%5Ctau%5Cacute%5Calpha%7E%5Ctau%5Calpha%7E%5Ckappa%5Cacute%5Calpha%5Cnu%5Calpha%5Cmu%5Cepsilon%7E%5Cmu%5Cepsilon%7E%5Ctau%5Calpha%7EE%5Clambda%5Clambda%5Ceta%5Cnu%5Ciota%5Ckappa%5Cacute%5Calpha%7E%5Crho%5Cepsilon%7E%5Cmu%5Calpha%5Clambda%5Cacute%5Calpha%5Ckappa%5Cepsilon%5Cvarsigma');
>> greektitle = repmat(greektitle,[1,1,3]); % make rgb so unaffected by colormap
>> axes; imagesc(greektitle); axis equal off;
>> P=get(gca,'position'); set(gca,'position',[P(1),0.9,P(3),0.1]); % place on top
>> saveas(gcf,'out.png','png')
Related
I'm making a .ipynb as a tutorial for neural networks.
Sometimes I need to add diagrams.
What I'm doing currently is drawing them on paper, taking a photo with my iPhone and rendering the .png in a markdown cell with e.g. ![BackProp](backprop.png).
However this sucks on a few different levels. It means I have to supply a bunch of media files when distributing the notebook. Also tweaking a diagram requires from-scratch--reworking. And it looks clumsy.
I tried a couple of approaches, but couldn't get anything to work:
It should be possible to render diagrams in LaTeX, and VSCode's .ipynb renderer handles stuff like $x^2 + y^2$. ChatGPT gave me:
\begin{tikzpicture}[x=1.5cm, y=1.5cm, >=stealth]
\draw[->] (-0.5,0) -- (4.5,0) node[right] {$x_1, x_2, \dots, x_N$};
\draw[->] (0,-0.5) -- (0,2.5);
\foreach \i in {1,2,...,4}
{
\filldraw[black] (\i,0) circle (0.1);
}
\draw[black, ->] (2,-0.3) -- (2,0.3);
\draw[black, ->] (2,0.3) -- (2,1.7) node[above] {$\sum_{i=1}^{N}w_ix_i + b$};
\draw[black, ->] (2,1.7) -- (2,2.2) node[above] {$\sigma(\cdot)$};
\draw[->] (2,2.2) -- (4.5,2.2) node[right] {Output};
\end{tikzpicture}
... but this gives "ParseError: no such environment: tikzpicture" -- and it looks like I'd have to pip-install https://github.com/mkrphys/ipython-tikzmagic
graphviz might be possible, however (1) I can't get it working with a markdown cell, and (2) even though it does work in a Python cell (after brew install graphviz and pip install graphviz),
import graphviz as gv
dot = gv.Digraph()
dot.edge("X6", "X7", label="$\sigma(\cdot)$")
dot
... still won't render LaTeX in the diagram.
Is there any out-of-the-box solution that wouldn't require my students having to fiddle with installations?
And if not, is there a recommended path?
I get an error, when I try to start gnuplot via cygwin (see below): Gnuplot does not seem to know the wxt-term, but according to this page (https://cygwin.com/pipermail/cygwin-announce/2020-July/009620.html), gnuplot should be able to know it.
After this I can use gnuplot by hand, e.g. typing in comments and it works normal.
But usually a have automatic plot programs and the error will cause the program to crash, so I can't work with it properly.
Is there any way to force gnuplot to ignore the error? Or can I start gnuplot directly with a certain terminal (e.g. png)?
Thanks
Sandra
$ gnuplot
G N U P L O T
Version 5.4 patchlevel 0 last modified 2020-07-13
Copyright (C) 1986-1993, 1998, 2004, 2007-2020
Thomas Williams, Colin Kelley and many others
gnuplot home: http://www.gnuplot.info
faq, bugs, etc: type "help FAQ"
immediate help: type "help" (plot window: hit 'h')
Terminal type is now 'unknown'
set term wxt
^
unknown or ambiguous terminal type; type just 'set terminal' for a list
WARNING: Error during initialization
gnuplot>```
Not tested but I suspect you need to use the gnuplot-wx
package as there are several gnuplot packages:
gnuplot-base A command-line driven interactive function plotting utility
gnuplot-doc A command-line driven interactive function plotting utility
gnuplot-qt5 A command-line driven interactive function plotting utility
gnuplot-wx A command-line driven interactive function plotting utility
gnuplot-X11 A command-line driven interactive function plotting utility
https://cygwin.com/packages/summary/gnuplot-wx.html
"Is there any way to force gnuplot to ignore the error?" No. When a gnuplot executable is built, someone has to choose which terminal types to include. This usually depends on what support libraries they have available to them when building it. Apparently your gnuplot executable was built without the wxt terminal. If you really need that particular output mode you will need to find a different gnuplot executable or build one yourself.
On the other hand - "can I start gnuplot directly with a certain terminal (e.g. png)?". Yes. There are at least three ways to do this.
Define an environmental variable GNUTERM. For example
export GNUTERM="png truecolor size 700,500"
(But that's a linux command. I don't whether there is an equivalent on Windows)
Edit the initialization file to contain a line such as
set term png truecolor size 700,500
From the "help" text:
When gnuplot is run, it first looks for a system-wide initialization file
gnuplotrc. The location of this file is determined when the program is built
and is reported by show loadpath. The program then looks in the user's HOME
directory for a file called .gnuplot on Unix-like systems or GNUPLOT.INI on
other systems. (OS/2 will look for it in the directory named in
the environment variable GNUPLOT; Windows will use APPDATA).
Give the "set term" command as part of the command line when you run gnuplot:
gnuplot -e "set term png truecolor size 700,500"
I am plotting the (postscript) ps file using the ghostscript in the terminal.
When I use the command"gs file.ps", it always gives the portrait orientation like following
enter image description here
do you know how could I rotate the plot with 90 degree with landscape orientation?
Without seeing the input file its not really possible to tell. However, the simple answer is that you need to produce your PostScript program so that it prints on landscape media.
Most likely you created the program by printing to a device which was described as using portrait media. So the application generated PostScript which would fit on that media.
You could edit the PostScript program, or you could try getting Ghostscript to do this for you. It may not work, it depends on how the program is written.
If you set the Ghostscript media to the size and orientation you want, tell Ghostscript the media is 'fixed' so that programs can't change it, and then tell Ghostscript to 'fit' the content, then it will choose the orientation which fits best.
Example command line:
gs -sDEVICE=<insert here> -sOutputFile=<your path> -dDEVICEWIDTHPOINTS=612 -dDEVICEHEIGHTPOINTS=792 -dFIXEDMEDIA -dFitPage <input.ps>
That sets up US Letter media (612x792 points), makes it fixed and requests the content fit the page.
If that doesn't work for you then I'd need to see the inptu PostScript program before offering further suggestions.
In R I always like to print out the script since it gives a good overview and one can adjust eventual errors. I like the syntax highlighting in R-Studio because it facilitates reading and fast comprehension of code.
Is there a way to print out the text with the highlighting I see in the editor?
Its not an R-Studio solution, but notepad++ will print R source with syntax highlighting.
RStudio will not print in colour, but it's easy to save the code as a PDF; in this case the syntax format is preserved. My favourite package is knitr.
library(knitr)
stitch("file_name.R")
The default output is PDF/Markup in .tex. If you prefer not to typeset, running the below will export as .html
stitch(script="file_name.R", system.file("misc", "knitr-template.Rhtml", package="knitr"))
Brief explanation
The reason this is an answer to this question in because of the last line of the question:
Is there a way to print out the text with the highlighting I see in
the editor?
so we are not limited to only and only using Rstudio software here.
After exploring the awesome answer by #rrg and realizing that it runs the code line by line, I wrote a comment below his answer and continued googling. My problem is that the code I wrote is so large and so time consuming to run that running it for the sake of having a syntax highlighted version is not feasible.
Most of the solution out there online involves having notepad++ which is a Windows application and I'm a dedicated Linux user, so I searched for a way I can do this in Linux (and possibly Mac)
The way I solved it:
Inspired by a blog post, I used the famous and beloved Vim to convert R to syntax highlighted HTML and then because you can open HTML in your browser, you can what ever you want with it (print, screenshot, etc.)
Activate synax highlighting in Vim:
open terminal
then open the vim config file by typing vim ~/.vimrc
press i from keyboard to go to "insert mode"
go to the end of the file using arrow keys on your keyboard
type syntax on at the end of the file
now you need to save and exit. For this you need to press Esc button from keyboard to come out of "insert mode" and then type :x and press Enter to save and close the file.
if you want to change the color scheme of the syntax highlighting, visit the bottom part of this website
From terminal open your file with Vim:
vim YOUR_FILE_PATH
Having you R code open in vim, you can turn on the line numbers if you like by pressing Esc and then write :set number and press Enter.
For converting R to HTML, press Esc to make sure you are not in "insert mode" and then type :TOhtml and press Enter. This will result is having a split window in terminal, half is your R code and the other half id your new HTML code.
For saving the files, type :x along with Enter button from keyboard twice to save both files (your R file will be unchanged if you have not typed anything extra in it and your HTML file will be created with the same name near your R code)
Now open it with your favorite browser (in my case Vivaldi) and do what ever you want (in my case converting the whole HTML into PNG)
Best way:
download https://github.com/jaredpetersen/codeprinter and paste in the r code. then choose syntax highlighting Xcode
For those using a Mac (and thus without access to Notepad++) cutting and pasting into Xcode and printing from there will also work.
As with Ron Jensen's earlier comment, this isn't an R Studio solution, but in the interests of "just getting it to work", I hope this helps someone.
I just started using ipython, and I'm creating figures such as:
fig, axes = plt.subplots()
xs = range(0,100)
axes.plot(xs, [x*x for x in xs], 'r')
I know that the figures can be rendered as svgs, see here. Unfortunately, the figures are always rendered as a rasterized image. The rasterized images become very ugly when I'm using the notebook's zoom feature. Is there a way to change this behavior, such that figures are displayed as svg by default?
The magic I was looking for:
%matplotlib inline
%config InlineBackend.figure_format = 'svg'
import matplotlib.pyplot as plt
Alternatively you might still want to show png but save a figure into a file:
plt.savefig(fig_filename, format='svg')
You can change the default figure format in the ipython profile configuration files. What I did was create a configuration profile especially for the notebook server, using:
ipython profile create nbserver
At the command line. This creates a whole bunch of files under ~/.ipython/profile_nbserver which have example lines for almost every setting you could want to change (it might be somewhere such as ~/.config/ipython instead depending on your OS, not sure about where it would be under windows). You need to look in the file ipython_notebook_config.py. You should then add the the line:
c.InlineBackend.figure_formats = ['svg']
Note that this only applied to IPython 3.x, and that you can also specify additional formats as per #HarrySchreiner's comment. For IPython 2.x, you should set c.InlineBackEnd.figure_format='svg'. To use this profile you should start the notebook with
ipython notebook --profile=nbserver
If this is too much trouble then don't give a profile name when running create, and modify the default profile instead.
Also, you may want to have the line
c.IPKernelApp.matplotlib = 'inline'
so that each notebook will automatically start with the matplotlib inline backend used.
Originally I also wanted to use the svg backend instead of png to enable zooming etc. However, I found that certain plots, such as pcolor with a large number of points can just kill my browser when using the svg backend. So I find it easier to use png, and just use the xlim and ylim commands to zoom in manually if I need to.
Also, you should definitely tweak the line c.InlineBackend.rc to set more reasonable defaults for the figure size and the fonts used.
edit
Current recommended best practice is not to use pylab, but to explicitly import matplotlib and numpy instead, so I modified my answer to stop encouraging this. See this post for the reasons why:
http://carreau.github.io/posts/10-No-PyLab-Thanks.html
Also, if svg rendering is too slow for particular plot elements (such as pcolor or plot_surface), you can pass the option rasterized=True to these plot commands. This means that those particular parts of the plot will have fast pixel based rendering, but all the other plot elements will be nicely vectorized.