How to make dashed / dotted / dash-dotted line in octave? - plot

I'd like to create monochrome diagram/graph in octave using plot command.
That is why I'd like make different lines of graphs with using line style, for example dashed/dotted/dash-dotted styles. Standard plot suggests several styles for line, but none of them looks like listed variants.
EDIT-1:
Standard plot styles are inapplicable for my case: such styles as ":", "-.", "--" don't work, octave draws solid lines in any case. Furthermore, diamonds and squares (d and s options) are ugly and disproportionate big. May be it will be helpful information: I'm using Octave under Windows.
EDIT-2: For example, such command plot(A(:,1),A(:,2),"-.dk") gives me such (inapplicable !!!) figure
More specifically I want something like this (in part of line style)
(Picture from article: McCallum and K. Nigam. 1998. A comparison of event models for Naive Bayes text classification. In Proceedings of AAAI-98 Workshop on Learning for Text Categorization)

These can be set with the FMT argument of plot. Basically, these seem to be your options (see the manual entrey on line styles):
"-" solid lines
":" points
"-."dash followed by dot
"--" dashed
"none" no line (only markers)
There is also the option "." for dots but this is for the actual data points, not the line. So to recreate your picture, something like the following should work
plot (multinominal, "-dk", "MarkerFaceColor", "k")
hold on;
plot (mv-bernoulli, ":sk", "MarkerFaceColor", "k")
The syntax may look a bit strange but here's how to read it. For -dk, - is for solid line, d for diamond shaped marker, and k for black colour (b would be for blue). On :sk, it's dotted line and square shaped marker in black colour.
See the section on the manual for advanced plotting.
EDIT: see the comments below. This may not work in very old versions of Octave.

Well, I found a simple solution by myself (using Google ;))
For gaining monochrome diagram/graph with a different style of lines in Octave, we don't need to use plot's styles like "--" or "-." (because they do not work).
Just one thing we need is the command print. Monochrome figures can be created for example in the eps format:
print -deps "diagram.eps"
This gives me quite a nice picture:

I had the same problem and I think that the solution to make visible the line style is changing the linewidth. Many linestyles are not distinguished when the default linewidth value is used (which is 1).
Try the following code and see if it works:
x = ( 0:0.4:10 );
f = sin(x) .* exp(-4 .* x);
g = sin(x);
plot(x,f,'r:','linewidth',5,x,g,'-.','linewidth',2)
print(gcf,"PlotSimple.pdf")

Related

Plot Order of plots and all drawn elements like line.new or label.new

It was my understanding that the plot order was the same as the occurrence in the code. So if I plotted a line on code line 23 it would be plotted before (and appear behind) a label that was defined from code line 98.
In a workaround to my last question, I am using a line set to 30 px and a transparency of 75 to create a fill. The problem is it is plotting over the top of labels that are defined much later in the code and because of their location should be plotting on top of the line, but they are not.
I have searched everywhere, pine manual vs 4, Kodafy, and here on Stack to find exactly what the output order of drawing, labels, line, and plots are.
If anyone knows the solution to my specific problem or where I can find the information resources to resolve it myself I would be very grateful.
Last Post referred to above: https://stackoverflow.com/questions/69236171/i-want-to-fill-between-two-extended-line-new-pine-script-is-not-having-it-√/69241461#69241461
Thanks, Michael
try adding this to you study() line:
explicit_plot_zorder = true
from the refman:
"explicit_plot_zorder (const bool) Specifies the order in which the indicator's plots, fills, and hlines are rendered. If true, the plots will be drawn based on the order in which they appear in the indicator's code, each newer plot being drawn above the previous ones. This only applies to plot*() functions, fill, and hline. Optional. The default is false."
Hope that can fix your problem
Cheers, and best of luck with your trading and coding

How to remove horizontal grid lines and get plain white background on ROC graph

I am conducting a ROC curve analysis in Stata. However, I am having trouble with the commands needed to get a plain white background plot.
I would like to:
remove the faint horizontal grid lines in the plot
remove the blue fill outside of the plot region
move the legend to the right upper-hand side (without a border/fill)
The following command was used to generate the ROC curve for a nonparametric ROC analysis without covariates:
roctab outcomedeath biomarkerlevel, binomial graph rlopts(lcolor(none) lpattern(shortdash)) legend(on)
As Nick implied, providing a reproducible example is the best way to help others on SO to help you.
Nevertheless, using the example from the roctab help file, we can see the standard Stata graph would look something like this:
webuse hanley, clear
roctab disease rating, graph
I like to use the scheme cleanplots (authored by Trenton Mize), which you can install with the command:
net install cleanplots, from("https://tdmize.github.io/data/cleanplots")
You can then either set it as your permanent scheme, or call it explicitly when you call your graph. For example:
* Option 1: set to cleanplots permanently (or until I change to something else)
set scheme cleanplots, perm
* Option 2: set to cleanplots just for this session
set scheme cleanplots
*Option 3: call cleanplots explicitly by adding this option when you call your graph
, scheme(cleanplots)
You can then run the graph command, which will give you something like this:
roctab disease rating, graph scheme(cleanplots) //i'm assuming you went with Option 3
I personally think this cleans up the graph significantly (removing the blue fill around the plot, adding a bit more space between y-axis and x-axis titles and their corresponding axes, rotating the ylabels so they're more easily readable, etc.). To then get the other two items you want (moving the legend and removing the faint gridlines), you just need to add in a few more options:
roctab disease rating, graph legend(on ring(1) row(2) pos(2)) ylab(, nogrid) xlab(, nogrid)
Note the above removes both horizontal and vertical grid lines, but if you only want to remove the horizontal ones just delete the bit that reads xlab(, nogrid). And if you want to move the legend onto the plotregion (it's currently outside of it, see p.3 of this documentation), you should change the value of ring() from 1 to 0.
Finally it's worth noting that whenever a help file says that you can pass through twoway_options which the roctab help file does, you can use any twoway options. I accept that still leaves a lot of room for error and discovery, but still thought it was worth mentioning.

Have a transparent background in a plot exported from Octave

I am using portable Octave 5.1.0 under Win 10.
I mean to write a plot to png with transparent background.
Disclaimer:
This question is similar to the two linked below.
I opted asking the present different question since I am adding further relevant information (by the same token, question #2 below was not a dupe of #1).
This is what I found:
print(gcf,'-dpngalpha', 'myplot.png');, suggested in Saving a plot in Octave with transparent background, does not work for me.
It is remarkable that I did not find documentation on this option.
This answer has a couple of issues for me: 1) for some unknown reason convert does nothing. 2) The requirement of an external package makes it cumbersome. For instance, I cannot simply send my Octave code to someone else for him to use it.
Option svgconvert is the only official documentation I found.
But it would not apply to a png, e.g.
imwrite seems to have the capability to write with transparency, but I couldn't find a way to transform a plot into and image suitable for imwrite.
(See also Matlab documentation).
Perhaps this is a possible route...
Is there any option available in Octave?
Related:
Saving a plot in Octave with transparent background
Printing / saving a plot as a png file with an alpha channel issue in Octave
http://mlab.no/blog/2014/06/image-transparency-overlay-with-gnu-octave-using-ycbcr/
The imwrite option seems to work. First create the image file img_fname, then create an alpha layer for it.
It would be interesting to know if one could avoid the intermediate non-transparent file.
EDIT:
I managed to create the image directly from my plot, instead of requiring the intermediate file.
x = -10:0.1:10;
plot (x, sin (x));
# Print figure directly to image instead of file
im = print(gcf, '-RGBImage');
tcolor = [255 255 255];
alpha(:,:) = 255 * ( 1 - (im(:,:,1) == tcolor(1)) .* (im(:,:,2) == tcolor(2)) .* (im(:,:,3) == tcolor(3)) );
imwrite(im, 'temp.png', 'Alpha', alpha);
Notes:
With a little simple algebra one could add transparency for any number of colors, and any opacity level for each color.
Moreover, one could move this into a function.
The multiplication of im and tcolor could be possibly vectorized as well.
Related:
https://www.mathworks.com/matlabcentral/answers/57664-how-to-add-alpha-channel-to-the-image-and-convert-that-image-into-png-format

Arrow/Vector Notation in R language

Is there some functionality to do arrow notation in R? I'm looking for something similar to hat(x), tilde(x), dot(x), ring(x) and bar(xy), mentioned in http://stat.ethz.ch/R-manual/R-devel/library/grDevices/html/plotmath.html.
[Update]
By "arrow notation", I mean vector notation. Like the one in the following image.
demo(plotmath) shows you the possibilities for drawing arrows in plot text. Examples include:
x %=>% y # double right arrow for implies
x %->% y # single right arrow for function mapping
Update based upon the comment:
There is no arrow accent available. You can hack one using atop(phantom(0) %->% phantom(0), x), but it doesn't look great because the arrow is too high up.

Plot 3D mesh in Maxima without colored surface

I have a 1-dimensional list x in Maxima with 16 different elements, and plotted every possible product of two elements as a 3D plot:
g(u,v) := float('x[round(u)]*'x[round(v)]);
plot3d(g(u,v),[u,1,16],[v,1,16],[grid,15,15]);
Which yields this result:
http://i.stack.imgur.com/uKwfe.png
My desired result is having only the contour lines, i.e. the mesh. I don't want the coloured surface.
This seems like a trivial task, but the manual is very unclear on this. It says that usually, you already have only the mesh, but this isn't the case.
Using wxMaxima 12.04.0 on Windows.
Looks like the key is to get the Gnuplot output file to contain the line
set style data lines
Maxima has its own idea about "set style ..." which you can see by
set_plot_option ([plot_format, gnuplot]);
and then inspecting the output file ($HOME/maxout.gnuplot by default). I don't know how to convince Maxima to output a different style command. As a last resort you could edit maxout.gnuplot by hand.
g(u,v) := float('x[round(u)]*'x[round(v)]);
plot3d(g(u,v),[u,1,16],[v,1,16],[grid,15,15], [palette, false]);
The [palette, false] option turns off surface coloring and draws only the mesh. But you'll still get hidden line removal, which Maxima automatically turns on.
To get a transparent wire mesh, do this:
plot3d(g(u,v),[u,1,16],[v,1,16],[grid,15,15], [palette, false],
[gnuplot_postamble, "unset hidden3d;"]);

Resources