3D Boxes (histograms) Gnuplot with cairolatex (or epslatex) - plot

I would like to plot 3D graphics using histograms (3D boxes) in gnuplot. However I use epslatex or cairolatex, and the demonstrations I used from the gnuplot demo site use a command:
set boxdepth
And this command always gives the error in my script.
The image I want to get looks similar to this:
Image link: http://www.gnuplot.info/demo_cvs/3dboxes.html
My basic script is this:
# Change filename to whatever you want.
filename = "fig4"
# LaTeX amsmath and utf8 input support.
set terminal cairolatex size 9cm,9cm color colortext standalone lw 4 header \
"\\usepackage{amsmath}\
\\usepackage[utf8]{inputenc}"
# Don't change output name
set output "gptemp.tex"
unset key
splot 'data.dat' with boxes
set out
system sprintf("pdflatex\
-interaction batchmode gptemp.tex &&\
mv gptemp.pdf %s.pdf &&\
rm -f gptemp*", filename)

The capability to draw 3D boxes is new, and only present in the gnuplot development version (5.3).

Related

Passing preamble to tikzmagic %%tikz in Jupyter notebook

I am using the tikzmagic extension with a Jupyter notebook to embed some TikZ diagrams into the notebook. (I am open to alternatives if there is a better way.)
In one cell, I create an iPython variable preamble like so:
preamble=r'''\tikzset{terminal/.style={
rectangle, minimum size=6mm, rounded corners=3mm, very thick, draw=black!50,
top color=white, bottom color=black!20, font=\ttfamily}}'''
In a subsequent cell, I try to use that variable like this:
%%tikz -f svg -l calc,positioning,shapes.misc -x $preamble
But that ends up generating LaTeX code like
% ⋮
\usetikzlibrary{shapes.misc}
\tikzset{terminal/.style={rectangle,
\begin{document}
% ⋮
It seems to terminate the argument at the ␣ (<space>). If I use
%%tikz -f svg -l calc,positioning,shapes.misc -x "$preamble"
It generates LaTeX code like
% ⋮
\usetikzlibrary{shapes.misc}
"\tikzset{terminal/.style={rectangle, minimum size=6mm, rounded corners=3mm, very thick, draw=black!50,
top color=white, bottom color=black!20, font=\ttfamily}}"
\begin{document}
% ⋮
My apologies if this is the wrong place to ask, but I thought TeX people might have encountered this problem, even though the fault is probably mine or in the Python source.

Composing a new graphic in R with magick from multiple existing images

I've created a table with the excellent gt package. Since it was a long table, my code creates the table in two halves. I save both halves to disk as png files then use the magick package's image_append() to composite them side-by-side as a new png file. All good.
Now, with magick, I'd like to compose a final graphic with a logo, some title text and source notes using image_annotate(), and my saved table, all laid out nicely.
I'm stuck trying to understand the right way to do that. I have all the graphical pieces, but I don't know how to create new, blank graphic with magick and then lay those pieces out in the locations I want them so that the finished product looks like this:
There are a lot of ways to create text images in Imagemagick. But here is likely the easiest for you to use and convert to R. The following is command line Imagemagick.
Logo:
Table Text Image:
Steps: (In subsequent command)
- Line 1: load imagemagick convert
- Line 2: create 500x500 white background image
- Line 3: insert the logo image at +20+20 relative to top left
- Line 4: add title text via -annotate
- Line 5: add sub-title text via -annotate
- Line 6: insert the preformed table image below those
- Line 7: add the source notes text via -annotate
- Line 8: save the resulting png file to disk
Command:
convert \
-size 500x500 xc:white \
rainbow_logo.png -gravity northwest -geometry +20+20 -compose over -composite \
-font arial -fill black -pointsize 48 -annotate +125+15 "TITLE TEXT" \
-font arial -fill black -pointsize 32 -annotate +125+65 "SUB-TITLE TEXT" \
lorem.png -gravity northwest -geometry +20+140 -compose over -composite \
-font arial -fill black -pointsize 18 -annotate +20+455 "SOURCE NOTES" \
result2.png
Result:

Gnuplot buttons greyed out

For years, I have used gnuplot from shell scripting and from the command line like this:
$ printf "1 2\n2 4\n3 6\n" > data.txt
$ echo "plot \"data.txt\" using 1:2" | gnuplot -persist
$
This gives an interactive plot with functioning buttons to toggle the grid, replot, apply autoscale and so on. Under my fresh installation of Ubuntu 18.04, these buttons are grey and disabled when gnuplot is operated like above. Alternatively:
$ gnuplot
G N U P L O T
Version 5.2 patchlevel 2 last modified 2017-11-01
Copyright (C) 1986-1993, 1998, 2004, 2007-2017
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 'wxt'
gnuplot> plot "data.txt" using 1:2
gnuplot>
This gives functioning buttons.
$ gnuplot -e "plot \"data.txt\" using 1:2"
$
This gives grey, disabled buttons again. How do I get the buttons to function in the first, scriptable method?
*** Edit below **********************
On at least one of my 14.04 machines the gnuplot version is indeed rather old: Version 4.6 patchlevel 4 last modified 2013-10-02. Using gnuplot -e "plot \"data.txt\" using 1:2; pause mouse close; exit" & keeps the buttons enabled... but so does echo "plot \"data.txt\" using 1:2; pause mouse close;" | gnuplot & on both Gnuplot versions. So thanks for your answer.

How to colorize a black-transparent PNG icon with ImageMagick

How do I a colorize a black PNG image that has a transparent background using ImageMagick?
Use case:
You have several PNG images like this:
And I want to colorize them like this:
I want to use ImageMagick's convert command, allowing for scripting to process hundreds of icons at a time.
You can use one of the following commands:
$ convert input.png +level-colors "red", output.png
$ convert input.png +level-colors "rgb(255,0,0)", output.png
$ convert input.png +level-colors "#ff0000", output.png
Note that the , character is important here. On the left side of the , character we tell convert which color should replace black and on right side what color should replace white. Therefore nothing should be given after the , character.
Source
... how do I colorize black & transparent PNG images [...] to colorize them like this [...] using ImageMagick
The -fill <COLOR> option works fantastic for this purpose. You can replace "#1bbfc9" with a human-readable name (e.g. "red") or an HTML color code.
convert target-black.png -fill "#1bbfc9" -colorize 100 target-blue.png
... allowing to script and process hundreds of icons at a time
Using the find command, you can recurse hundreds.
Warning: This will replace the originals.
find path/to/files -iname '*.png' -exec convert "{}" -fill "#1bbfc9" -colorize 100 "{}" \;
With ImageMagick, you can process a whole folder of images at one time with mogrify rather than convert if you want all the same color. Create a new output directory to hold the colorized files. Then cd to the folder holding your images.
cd path_to/image_folder
mogrify -format png -path path_to/new_folder -fill "cyan" -colorize 100 *.png
Where replace path_to with your actual path.
You may use color names, hex colors or rgb(...) colors in the fill command, but enclose them in quotes on Linux/Mac OSX. Quotes are not needed for Windows, but should not cause any issues if double quotes.
See mogrify

Invert PNG graphics file with a non-interactive command

I'm using DruTex, which is a Drupal module to embed Latex equations. The context of the equation is marked, and a Latex interpreter will generate a PNG file:
dvipng -o [IMG_FILE] -D [DPI] -T tight [TMP_DIR]/[HASH].dvi
The dvipng utility is used to generate a PNG from Latex's DVI file. That's good so far, but I could need black background and white foreground for these equations, since otherwise they are hard to read, because they appear in a dark-themed way.
convert (from Imagemagick) doesn't have an -invert flag. Neither does dvipng. So is there a way to invert a png file? I can add something to that routine like:
batch_invert -input [IMG_FILE] -out [IMG_FILE]
However I do not know how I can implement that.
convert has a -negate option that works.
Example:
convert -negate input.png output.png

Resources