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:
Related
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"
...
please let me know any other system/code I need to include, as I am not as familiar with writing out images to my computer. I am creating 360 png files as follows:
for(theta in 1:360){
ic=as.character(theta)
if(theta<10) ic=paste("00",ic,sep="")
if(theta>=10 & theta<100) ic=paste("0",ic,sep="") # make filenames the same length
fn=paste("c:iris360\\HW4_",ic,".png",sep="") #filename
png(fn,width=1000,height=1000) # save as *.png
p3(X1,X2, r=100,theta=theta,mainL=paste("theta =",theta))
# legend("topleft",pch=16,cex=1.5,col=allcl)
dev.off()
}
system("magick c:iris360\\HW4*.png c:iris.gif")
where p3 is just a function that takes my matrices X1 and X2 and plots the points and their segments(let me know if I need to include it as well). However, I get this error:
magick: must specify image size iris360HW4*.png' # error/raw.c/ReadRAWImage/140.
I am unable to open the gif file, as my mac says it is damaged or uses a file format that preview does not recognize.
Update 1: I replaced fn's declaration with
fn <- sprintf("c:iris360/HW4_%03i.png", theta)
as well as replacing ic with sprintf("%03i", theta) everywhere it appeared, but still got the same specify image size error.
When I run the system command into my terminal, I still get the same error asking me to specify the image size.
Magick needs to know several things (e.g., image size, delay between frames, images to use, destination file name) in order to convert a stack of png into a gif. See GIF Animations and Animation Meta-data
magick -delay 100 -size 100x100 xc:SkyBlue \
-page +5+10 balloon.gif -page +35+30 medical.gif \
-page +62+50 present.gif -page +10+55 shading.gif \
-loop 0 animation.gif
So it looks like you need to change
system("magick c:iris360\\HW4*.png c:iris.gif")
to something more like
system("magick -delay 10 -size 100x100 —loop 0 c:iris360\\HW4*.png c:iris.gif")
I've created a file in notepad and saved it as ANSI and .dat file. The file structure looks like:
2019 371320
2018 352137
2017 323201
2016 302271
2015 291377
2014 282730
2013 273467
2012 257093
2011 244541
2010 223488
2009 216949
2008 197778
(...)
Then gnuplot terminal being opened I set the settings I want to and after the plot "dates1.dat" using 2:xticlabels(1) with boxes lt rgb "#406090" an error pops up:
Warning! Cannot find or open file "dates1.dat"
No data in plot
Whole settings:
# Output to PNG, with Verdana 8pt font
set terminal pngcairo nocrop enhanced font "verdana,8" size 640,300
# Don't show the legend in the chart
set nokey
# Thinner, filled bars
set boxwidth 0.4
set style fill solid 1.00
# Set a title and Y label. The X label is obviously months, so we don't set it.
set title "Number of registrations per month" font ",14" tc rgb "#606060"
set ylabel "Registrations (thousands)"
# Rotate X labels and get rid of the small stripes at the top (nomirror)
set xtics nomirror rotate by -45
# Show human-readable Y-axis. E.g. "100 k" instead of 100000.
set format y '%.0s %c'
# Replace small stripes on the Y-axis with a horizontal gridlines
set tic scale 0
set grid ytics lc rgb "#505050"
# Remove border around chart
unset border
# Manual set the Y-axis range
set yrange [100000 to 300000]
set output "6.png"
plot "dates1.dat" using 2:xticlabels(1) with boxes lt rgb "#406090"
The dates1.dat file is full of data as I showed before. Any thoughts on how to fix the problem?
In the gnuplot console type pwd which will print the current working directory. Is your file located in this directory? If not either give the full path, e.g.
plot 'C:/myDir/subDir/dates1.dat' ...
or change the working directory with cd. Check help pwd and help cd.
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');
I'm using FontForge to create a ttf font from SVG files. But the baseline is all wrong and I can't understand how to set the baseline from the FontForge command line scriping tool.
Any ideas?
The baseline is where y = '0' in the cartesian grid system of the 'em square'. If you look at the emsize, its likely 1,000, and typically there are 200 units below the baseline and 800 units above.
You can move the glyphs so that their base point is on the baseline, ie, their point has a y value of 0
If you are using FF's python module, you'd do something like this to translate a single glyph:
import fontforge
import psMat
base_matrix = psMat.translate(0, 200)
# …
glyph.importOutlines(some_svg_file_object)
glyph.transform(base_matrix)