# On the exporting process from Mathematica in vector graphic

## 1) Preamble: the problem

So I was trying to make a plot of the visible spectrum of the hydrogen atom and I had lot of troubles with exporting it.

First I want to point that I have to use this plot in a LaTeX document, so I needed the package MaTeX, which you probably need to load to run my code. Also I really need vector graphic plots, and not the rasterised version; this would lead in the following to the problem of size files. Here's the listing.

(*Preamble: loading 2 packages of LaTeX and the MaTeX package for Mathematica*)
<< MaTeX
SetOptions[MaTeX,
"Preamble" -> {"\\usepackage{color}\\usepackage{siunitx}"}];

(* rgbSpec: That's a function for making the proper ColorFunction *)

rgbSpec[x_] := RGBColor @@ Piecewise[
{
{
{19/100 + 19/3000 (410 - x), 0, 1 - 6/300 (410 - x)},
380 <= x < 410},
{
{19/3000 (440 - x), 0, 1},
410 <= x < 440},
{
{0, 1 - (490 - x)/50, 1},
440 <= x < 490},
{{0, 1, (510 - x)/20},
490 <= x < 510},
{
{1 - (580 - x)/70, 1, 0},
510 <= x < 580},
{
{1, (640 - x)/60, 0},
580 <= x < 640},
{
{1, 0, 0},
640 <= x < 700},
{
{35/100 + 65/8000 (780 - x), 0, 0},
700 <= x <= 780}
}
]

myplot = Show[
DensityPlot[x,
{x, 380, 780},
{y, 0, 400},
ColorFunction -> (rgbSpec[#] &), (*Use of rgbSpec*)
ColorFunctionScaling -> False,
PlotRange -> {{380, 780}, {0, 400}},
Frame -> True,
FrameTicks -> {
{None, None},
{
{
{380, MaTeX, {0, 0.3}}, {420,
MaTeX[420, Magnification -> 1.6], {0, 0.3}},
{460, MaTeX, {0, 0.3}}, {500,
MaTeX[500, Magnification -> 1.6], {0, 0.3}},
{540, MaTeX, {0, 0.3}}, {580,
MaTeX[580, Magnification -> 1.6], {0, 0.3}},
{620, MaTeX, {0, 0.3}}, {660,
MaTeX[660, Magnification -> 1.6], {0, 0.3}},
{700, MaTeX, {0, 0.3}}, {740,
MaTeX[740, Magnification -> 1.6], {0, 0.3}},
{780, MaTeX, {0, 0.3}}, {380, "", {0, 0.2}},
{400, "", {0, 0.2}}, {420, "", {0, 0.2}},
{440, "", {0, 0.2}}, {460, "", {0, 0.2}},
{480, "", {0, 0.2}}, {500, "", {0, 0.2}},
{520, "", {0, 0.2}}, {540, "", {0, 0.2}},
{560, "", {0, 0.2}}, {580, "", {0, 0.2}},
{600, "", {0, 0.2}}, {620, "", {0, 0.2}},
{640, "", {0, 0.2}}, {660, "", {0, 0.2}},
{680, "", {0, 0.2}}, {700, "", {0, 0.2}},
{720, "", {0, 0.2}}, {740, "", {0, 0.2}},
{760, "", {0, 0.2}}, {780, "", {0, 0.2}}
},(* Emission wavelenghts *)
{
{656.2, MaTeX[656.2, Magnification -> 1.7], {0, 0.2}},
{486.0, MaTeX["486.0", Magnification -> 1.7], {0, 0.2}},
{434.0, MaTeX["434.0", Magnification -> 1.7], {0, 0.2}},
{410.1, MaTeX[410.1, Magnification -> 1.7], {0, 0.2}}
}
}
},
FrameLabel -> {MaTeX[
"\\text{Wavelenght~~}\\lambda~(\\si{\\nano\\meter})",
Magnification -> 2],
MaTeX["\\mathbf{H}~~", Magnification -> 2]},
AspectRatio -> Full,
ImageSize -> {1000, 200},
RotateLabel -> False
],
Graphics[Rectangle[{656.2 + .5, 0}, {656.2 - .5, 400}]],
Graphics[Rectangle[{486.0 + .5, 0}, {486.0 - .5, 400}]],
Graphics[Rectangle[{434.0 + .5, 0}, {434.0 - .5, 400}]],
Graphics[Rectangle[{410.1 + .5, 0}, {410.1 - .5, 400}]]
]


Now the product of all this code is this image (which I just screenshoted) Now, as the image was so far from the vector graphic that I wanted (if you full screen it you'll notice), I tried to export the image by right-clicking on the image and use the option Save graphic as... which lead me to the choice of the format of the image, the name and the possible options, as shown below Now, as the default exporting options were giving me low resolution and non-vector graphic images I choose, under Options...->Graphic containing transparency and Options...->Graphic containing smooth shading the Use Highest Quality Vector option which at first seemed to do exactly what I wanted but led to this strange output (when saved in PDF) As you can see there are strange white spaces (you maybe have to enlarge it) and transversal lines in the color gradient. So now I have solved the problem of vectorial plot, but I have the problem in the color gradient defined by the rgbSpec[x_] function.

## 2) The body: an attempt of solution...

I thought that increasing the PlotPoints could have been a nice idea, so I set them at 100 (it took more than half a minute to get the output) but the result is still looking ugly with some strange white dots above my color gradient and the visible strip of the changing color To see this effect you need eventually to open the file for full resolution image. Plus, the problem now is that I have a 22,3 MB image, which is not great if you want to put it in a TeX.

So I thought that the problem was the pdf format container, and I tried with the SVG format, with the same option Use Highest Quality Vector. Sadly the result is not vector graphic at all! I really can't understand this, but opening the output with Inkscape or Gapplin it's easy to notice this fact (as above I'm now posting just a detail of the picture) You can notice that is not vectorial because of the blur which shouldn't be there when zooming a SVG.

## 3)The end: what I ask and what I would like

I seek a vector graphic plot in PDF or SVG and a way to convert it in SVG maintaining is vectorial properties which is not 100 MB but in which the color gradient is uniform and without strange patterns.

I think that the bug is inside the ColorFunction` which doesn't fill properly the area so when it's printed in vector graphic it is not the same as the output you see on Mathematica.

• There is no need to tell us about how many days you worked on a problem, how frustrated you are, the stages of the work, etc. This makes your problem needlessly long and discourages anyone from reading it (and thus helping you). I think you can cut this problem down by more than 50% and urge you to do so. I for one will not work on the problem as it stands. – David G. Stork Mar 20 '18 at 21:10
• Is it ok now? You were faster than me, sorry for that... I added the part 2) to avoid answers of already tried solutions, anyway if there is still something it is not appropriate let me know. – opisthofulax Mar 20 '18 at 21:23