Logarithmic x and y axis for image plot - plot

I need to do this in a different way, since pcolor produces diagonal lines in the output file
h=pcolor(rand(16)); %The actual data comes from hist3
set(h,'EdgeColor','none');
colormap(gray(256));
set(gca,'yscale','log');
set(gca,'xscale','log');
print('test.png','-dpng','-r4800'); %Gives diagonal lines in text.png
Is there a simple workaround the bug. I use the FLTK backend.
Update
Switching to gnuplot removes the diagonal lines, but adds vertical and horizontal lines, but changes increases the plot margins too much.

Here is a "solution" to the bug. The idea is to disable anti-aliasing for graphics.
gswrapper.sh
#!/bin/bash
ARGS=()
ARGS+=("-dGraphicsAlphaBits=1")
for var in "$#"; do
[ "$var" != '-dGraphicsAlphaBits=4' ] && ARGS+=("$var")
done
gs "${ARGS[#]}"
Octave script:
h=pcolor(rand(16)); %The actual data comes from hist3
set(h,'EdgeColor','none');
colormap(gray(256));
set(gca,'yscale','log');
set(gca,'xscale','log');
print('test.png','-dpng','-r600','-G./gswrapper.sh');

Related

How to Print scalable figures with Octave and a Brother MFC-J625DW printer

My Printer is a Brother MFC-J625DW ink jet.
I wrote a simple circle and square plot, which I would like to give me scalable circles and squares.
I can get a figure1.I don't know how to print out the figure.
If I set axis(equal) then I am able to use prt screen and One Drive.
I can print out the image and with a ruler determine a scale factor.
There must be a way of specifying the printer and taking figure1 which doesn't relate to a print statement and print it directly from Octave.
Help.
Thank you, Yehuda
attached the code that doesn't print
%circleincart
r1=10.1/2 %inner circle
r2= 11.87/2 % Outer circle
s1=15.895 %square;
r4= 8.34/2;
t=[0:0.1:2*180];
thrd=pi/180*t;
x1=r1*cos(thrd);
y1=r1*sin(thrd);
x2=r2*cos(thrd);
y2=r2*sin(thrd);
x10=r1/7*cos(thrd);
y10=r1/7*sin(thrd);
x20=r2/7*cos(thrd);
y20=r2/7*sin(thrd);
x3=[-7.9475 ,-7.9475 ,7.9475, 7.9475, -7.9475];
y3=[-7.9475 ,7.9475 , 7.9475 -7.9475 -7.9475];
x30=x3/7; %7 is the scaling factor
y30=y3/7;
scfctrsmallest=r4/r2/7;
x40= scfctrsmallest*x2;
y40= scfctrsmallest*y2;
x5=[-10,10];
y5=[0,0];
x6=[0,0];
y6=[-10,10];
plot(x1,y1,x2,y2,x3,y3,x20,y20,x10,y10,x30,y30,x40,y40,x5,y5,x6,y6);
%plot(x5,y5,x6,y6);
axis("square")
%print -dpsc
%print (1,-PMFCJ625DW)
print figure1
print -dpsc
%print -dsvg "path/to/fig1"
% -djpg figure1
%print -dpng figure1
%print -PMFC-J625DW
%print (-PMFC-J625DW);
Succeeded with print screen and One Drive.
Couldn't get Octave to recognize printer (maybe a path problem).
Need way of Octave to print the figure1.

gnuplot - plot both from a data file and a gnuplot function in a single image

I have the following snippet:
set grid
set xlabel "Entropy"
set ylabel "Amortized work"
set xrange [-0.05:1.05]
set style line 1 linecolor rgb '#516db0' linetype 2 linewidth 5
f(x) = -1.3973 * x ** 2 + 1.3947 * x + 0.5796
F = '$-1.3973 x^2 + 1.3947 x + 0.5796$'
set terminal cairolatex pdf input size 700,700 color colortext
set key opaque box lc "black" linewidth 3
plot 'RatioVerboseData.dat', f(x)
set output
The data file RatioVerboseData.dat looks like this:
0.93070 0.290710
0.94060 0.281450
0.95050 0.254771
0.96040 0.241656
When I run the script with the gnuplot, it outputs:
plot 'RatioVerboseData.dat', f(x)
^
cairolatex terminal cannot write to standard output
"EntropyVerboseData.plt", line 15: util.c: No error
I use gnuplot 4.6.7 and MiKTeX-pdfTeX 4.10 (MiKTeX 22.7)
You need to specify an output file. Otherwise gnuplot tries to write back to the input terminal (stdout). That makes sense for some terminal types, e.g. the "dumb" terminal, and is not revelant for terminal type with their own display window, e.b. "qt", "wxt". But it cannot work for terminal types that need to create multiple output streams and then combine them to produce the final document, which covers most (all?) of the LaTeX terminal types.
Add a line:
set output "RatioVerboseData.tex"
Why are you using a 7.5 year old gnuplot version? Current version is 5.4.
I can reproduce your observation (on Win10 with gnuplot 4.6.7) that gnuplot gets stuck.
I couldn't find a hint in help cairolatex, but I guess if you don't add units to the size it will be interpreted as inches. But this does not yet explain why gnuplot freezes when you want to create a 700in x 700in large graph.
Anyway, if you add units, I guess at least in and cm are accepted and if you add the output file as #Ethan already suggested then it should work.
...
set terminal cairolatex pdf input size 7cm,7cm color colortext
set output "RatioVerboseData.tex"
...

tradingview pine script error "cannot use 'plot' in a local scope"

I am trying to write a simple if-then-else statement using the Pine language under Tradingview. What the code does is based upon user input.
If the box is checked, the plot the line.
If the box is not checked do not plot the line.
This is the code I have:
notPlot = -2000
var ch382= input(true, ".382")
if ch382
plot( ch382? bottom + diff * .382: noPlot, title="fib-.236", linewidth=3, color=color.orange )
How can I write this in a proper way?
If I try to run it, I get: “cannot use 'plot' in a local scope”
Any assistance would be greatly appreciated.
ETA: I found this thread below
How to put plot statement inside if statement
but -
what I need to do is to plot if the box is checked and ~not plot~ if the box is not checked.
ETA: figured out the issue. One would use "na" (in the case of plotting) to note that the line should not be displayed - my mistake ...
var ch382 = input(true, ".382")
plot( ch382? bottom + diff * .382: na, title="fib-.382", linewidth=3, color=color.orange )

Overlapping lines in Gnuplot when exporting

I'm trying to plot a discrete brownian path in gnuplot, which involves a lot of overlaping lines. This is how it's displayed in the qt terminal (I have generated the image with a screenshot):
Notice how the overlapping lines get colored in a stronger color, which is beautiful.
If I export it in png, with
set term pngcairo size 1366,768 enhanced
I obtain this:
All the lines have the same intensity. Setting transparent doesn't help, either.
The same happens with this MWE:
set term pngcairo size 1366,768 background '#000000' enhanced
set output "image.png"
unset key
set border 0
unset xtics
unset ytics
set samples 1e6
set xrange [0:0.1]
p sin(1/x) w l lw 0.3
set output
I'm running gnuplot -d each time so my local config does not get loaded. How should I export the plot to obtain the same effect as in the GUI?
Here are some results of my investigation :
I couldn't achieve beautiful results with pngcairo either. Opacity isn't added when 2 curves overlap each other.
Exporting to SVG and converting to PNG looked a bit better, either with inkscape -z -e image.png -w 1600 -h 1200 image.svg or convert -density 3000 -resize 1600x1200 image.svg image.png. This step could be included in gnuplot as a system command.
It is possible to export the qt render to png directly from the qt window. First menu icon on the left → Export to image
This process could in theory be automated directly from Gnuplot, without user interaction. A patch has been submitted : https://sourceforge.net/p/gnuplot/patches/665/. As far as I can tell, it hasn't been yet integrated into Gnuplot 5.0.x
Here is a related discussion on Gnuplot-dev.
If you feel adventurous, you could try to recompile Gnuplot with the applied patch. The submitter might be able to help you.
Very offtopic in this question, but as a workaround I have made a Julia script that replicates the image feeling that I am looking for. I will post it here in case anybody finds it useful.
using Images
function paint(Ny, Nx, iters=1e6; stepsize = 50)
randstep() = rand([-1;1])
x = Nx÷2
y = Ny÷2
M = zeros(Nx,Ny)
for i in 1:iters
rx = randstep()
ry = randstep()
for i in 1:stepsize
x = mod1(x+rx, Nx)
y = mod1(y+ry, Ny)
M[x,y] += 1
end
end
clamped = M/maximum(M)
img = [Colors.RGB(0,mm,0) for mm in clamped]
end
img = convert(Image,paint(1366,768,1e4,stepsize=10))
save("coolbrownianwalk.png", img)
This produces images like this:

Stata graph with no horizontal lines in the graph and no legend border

I am exporting my Stata graphs as *.eps in order to implement them in LaTeX. I'm using the following options:
xtline bhar_pct if decile==1 | decile==10 | decile==11, overlay ///graphregion(color(white)) bgcolor(white) legend(region(lwidth(none) label(1 "Portfolio 1") label(2 "Portfolio 10") label(3 "Hedge Portfolio (10 - 1)")) plot1(lpattern(solid) lwidth(medium) lcolor(gs1)) plot2(lpattern(longdash) lwidth(medium) lcolor(gs1)) plot3(lpattern("---#") lwidth(medium) lcolor(gs8)) xlabel(0 (10) 50) xtitle("") ylabel(-10 (2) 10, angle(0)) ytitle("BHAR (in %)")
But still: the background is white, but there are "super light blue gridlines" inside the graph as well as as the border of my legend. Moreover, the graph has an "overall" blue border as well. By now I am trimming the graph in order to remove this border, but there must be a way to create "plain" graphs?
I had to convert the *.eps file to png, but cannot post it due to lack of reputations. So here is a link to it:
http://www.converthub.com/working/done/93b7cfd46b432b1312f78912e645a5cb/aar_crisis1_dsue1.png
How about:
clear all
set more off
*----- example data -----
sysuse xtline1
xtset person day
*----- what you want -----
xtline calories, overlay graphregion(color(white)) bgcolor(white) ylabel(, nogrid) ///
legend(region(lcolor(white)))
?

Resources