I'm trying to use octave to draw root locuses and apparently the code for drawing it was written in the early 2000s so everything is far too small to see. I can't figure out how to modify everything to be at a visible size, and I shouldn't have to.
How do I configure gnuplot to make everything be a visible size by default? I can't find any info on how to configure it with google.
Edit:
Here's the code:
pkg load control;
s = tf('s');
rlocus((s+10)/(s*(s+1)*(s+20)))
That produces a plot that looks like this:
Thank you for the code. This may not be a full answer for you, but I'm writing this in the form of an answer in order to post images...
Your graph looks a bit weird indeed for a default graph. This is what your code produces on my system (Linux Mint, Octave v6.2.0) by default (i.e. using the qt toolkit):
It would be helpful to have some more information:
What operating system are you using?
What version of octave are you using?
What graphics toolkit are you using? (type graphics_toolkit in the octave console), and if this is not the default qt one, why is this the case?
Having said that, if you're happy to specify some graph settings yourself, it is certainly possible to specify fontsizes etc. E.g.
pkg load control;
s = tf('s');
rlocus((s+10)/(s*(s+1)*(s+20)))
set( gca, 'fontsize', 20 )
Pos = get( gcf, 'position' ); set( gcf, 'position', Pos + [0, 0, 500, 200] )
Related
I'm in the process of learning R (I'm still a newcomer on SO as well). Being very used to using Visual Studio Code, I decided to choose that over RStudio or RStudio Cloud.
One of the best parts of RStudio was that plots automatically resized/reshaped themselves if we resized the right pane. Moreover, in the tutorials I watched, plots involving map data automatically rendered in the correct aspect ratio (as seen on physical maps).
I replicated the code to make my own plot of the world map. Unfortunately it rendered as a square shape, and resizing the right pane does not affect its shape:
enter image description here
Am I missing any commonly used VSC extensions which can make plots resizeable like in RStudio? (I've installed only the most downloaded extension for R, by Yuki Ueda)
If not, can I modify my code to specify the exact dimensions I need the plot to have?
Thanks in advance!
You can add robust plot viewing options for R in VSCode by installing the httpgd package and then amending your JSON settings.
First, install httpgd via the R console:
install.packages("httpgd")
Then, open your JSON settings in VSCode by opening the Command Palette (either via Ctrl+Shift+P or via View > Command Palette) and then searching for "Preferences: Open Settings (JSON)", where you'll insert the following:
"r.plot.useHttpgd": true
You can add a comma after 'true' if needed (i.e. if there are other lines below that in your JSON settings).
Following that, restart VSCode and launch the R terminal inside it, and plot something using either ggplot2 or base R graphics:
plot(mtcars$mgp, mtcars$wt)
A plot viewer should then pop up in VSCode. You can either manually resize the window there, zoom in or out, or, my preference (particularly if I'm cycling through a series of already-plotted graphs), open it in an external browser where it'll automatically adjust to however you resize the window. After that, you can save or copy the image as needed.
You can specify the dimensions when you save the file. I usually use (approximately) the golden ratio:
ggsave("./earth.png", width = 16, height = 10)
The ggsave function reference explains how you can change units - options are c("in", "cm", "mm", "px").
I'm wondering is it possible to customise R help files so that certain text is colour coded and easier to read. rdoc already does this except that it sends the output to the console. I would instead, like it to be sent to the help panel (i'm using Rstudio). Is there any workaround for this?
If we run ?lm normally, we can see the usual help file in the help panel on the right below but when you do it again after using rdoc in Rstudio we get the help file colour coded which is great but its sent to the console output (left side). Ideally, we would like it to remain on display in the help panel as we are running code. The way it is now - it disappears the minute you run something.
?lm
#devtools::install_github("mdequeljoe/rdoc")
library(rdoc)
options(rdoc.by_section = FALSE)
rdoc(lm)
I want to put the code into my .rprofile similar to #csgillespie .rprofile. Note, if you follow his code you can use ?lm instead of having to call rdoc(lm) directly to produce the colour coded console output.
I have a feeling this can't be done easily (if at all?) but interested to hear any suggestions.
Thanks
This is possible, but a little involved. You'll need your own css file defined to do it, though it would be possible to create a function that writes appropriate css.
As a proof of concept, I have used a copy of the "R.css" file defined inside every package's "/html" folder, and just changed the h2 color to red, with the file saved locally as "my.css".
Anyway, once you have the css file, this function will show the appropriate help file with the appropriate styling in your R viewer window:
help_css <- function(func, css_file)
{
pack <- sub("^.*:(.*)>$", "\\1", capture.output(environment(func)))
func <- deparse(substitute(func))
x <- readLines(paste0(find.package(pack), "/html/", func, ".html"))
x[3] <- paste("<style>",
paste(readLines(css_file), collapse = "\n"),
"</style>")
writeLines(x, file.path(tempdir(), "test.html"))
myViewer <- getOption("viewer")
myViewer(file.path(tempdir(), "test.html"))
}
So, for example, if I do:
help_css(lm, "my.css")
I get:
As of RStudio v1.2 you can style RStudio's integrated help pane by creating a custom user theme (essentially an .rstheme file).
I've given help pane styling a try in extending the rscodeio theme (without colored syntax highlighting, though). The latest CSS code is found here.
The help pane styling is currently only available in the optional Tomorrow Night Bright (rscodeio) editor theme.
To use it right away, you can either
install the current rscodeio master branch using remotes:
remotes::install_github("anthonynorth/rscodeio")
And then activating the editor theme named Tomorrow Night Bright (rscodeio) under Tools → Global Options… → Appearance → Editor theme. A first attempt of the help pane CSS code is included.
or – recommended – install my fork's interim-merge branch which contains all my latest work[1] overhauling the package, including a new apply_theme parameter to activate the desired editor theme right away:
remotes::install_github("salim-b/rscodeio#interim-merge")
rscodeio::install_themes(apply_theme = "Tomorrow Night Bright (rscodeio)")
[1]: This has also been proposed upstream a while ago (1, 2) but I haven't heard back from the author since.
The result looks as follows (example for ?pal::as_string):
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.
I'm new here.
I've the same matter as this one but only using QtOctave; beside oct2mat pkg hasn't never been loaded on my pc.
Typing:
pkg unload oct2mat
octave returns:
error: package oct2mat is not installed
error: \share\octave\3.6.2\m\pkg\pkg.m at line 2170, column 9
Using plot function directly in Octave it works properly, very stange!
Can enybody help me?
Thanks in advance.
Addendum to #vinukn's answer, as it might be too cryptic.
Try this:
>>> graphics_toolkit
ans = fltk
>>> agts = available_graphics_toolkits
agts =
{
[1,1] = fltk
[1,2] = gnuplot
}
>>> graphics_toolkit(agts{2}) % This sets the graphics toolkit.
>>> plot([1 2 3 4])
That is, the default was FLTK, and I've set Gnuplot. Try each, they look slightly different to each other.
This is on my default installation of Octave 3.6.2 on Windows Vista, with QtOctave. (I've tried the most recent build of Octave, with built-in GUI, but after starting it never drew in its windows, so it was unusable at this stage, which is a shame as there are probably a handful of lines of code that need to be changed to make it work... Will wait until that is fixed. In the meantime, Gnuplot doesn't freeze.)
Also, here is a list of keys to use in the Gnuplot window. Especially note:
Right-click to draw a zoom box.
a to autoscale (back to default zoom).
p to go back to the most recent previous zoom.
Don't use QtOctave. It has been deprecated for a reason. See the GUI section in Octave FAQ to understand why the GUI doesn't work. It is specially true for things such as plots and dialog windows.
Take special note on the fact that QtOctave and others are specially sensitive to new versions of Octave. You are using Octave 3.6.2 while QtOctave was abandoned back in 3.2.X. Your options are (by order of what I recommend):
use Octave on its own, no QtOctave;
build from development sources to use the experimental GUI;
fix QtOctave (I actually don't recommend this one at all. Its website has been closed, and it would be too much work which would be better spent helping the Octave developers with the native GUI);
Actually,the reason behind this problem is default graphics toolkit fltk or qt. Qtoctave works with pipe, fltk does nt support pipe, ie fltk works inside octave. Pipe does nt support both text and image(gui) same time. The solution is change default toolkit to gnuplot.
This is observed running in batch. Given the following code snippet, I don't understand why R creates an empty jpeg file in Windows even though I am not calling a plot or graph. When I run similar code under Linux or OS X, the jpeg file is not created. I don't know ahead of time if the user is going to want a plot so I setup the filename(s) ahead of time and give them a name and location.
##
sink("c:\\temp\\test.lst")
jpeg(file="c:\\temp\\test%d.jpeg")
norm <- rnorm(100)
print(norm)
Any suggestions would be appreciated.
The ?jpeg help file (which also applies to bmp(), png() and tiff() devices) indicates that:
The ‘type = "windows"’ versions of these devices effectively plot
on a hidden screen and then copy the image to the required format.
This Windows-specific implementation detail most likely explains the difference in the behavior of Windows and *NIX systems.
On Windows, calling any of the functions above (and pdf() and postscript() as well) creates a file --- whether or not you then plot anything to that hidden screen. Except for pdf() (which produces files that I can't open with a viewer), the image that's registered on the plotting device is that of a white rectangle of height and width specified in the call to the specific device.
I wouldn't worry about it. if the prospect of zero-length files cluttering up the folder bothers you, you can clean up afterwards with something like
jpgs <- file.path("c:/temp", dir(pattern="c:/temp/test[0-9]*\\.jpeg"))
s <- file.info(jpgs)[["size"]]
for(i in seq_along(s))
if(s[i] == 0) file.remove(jpgs[i])