# How to export a plot into a file?

I am trying to save some graphics into a file, and it seems impossible.

x1 = Round[RandomVariate[NormalDistribution[325, 5], 25], 0.1];
x2 = Round[RandomVariate[NormalDistribution[325.5, 2], 25], 0.1];
x3 = Round[RandomVariate[NormalDistribution[327.5, 7], 25], 0.1];

h1 = Histogram[x1, 6, "Probability",
ChartLegends -> {"\!$$\*SubscriptBox[\(x$$, $$1$$]\)"},
ChartStyle -> {Directive[Red]},
PlotRange -> {{308, 342}, {0, 0.5}}];
h2 = Histogram[x2, 6, "Probability",
ChartLegends -> {"\!$$\*SubscriptBox[\(x$$, $$2$$]\)"},
ChartStyle -> {Directive[Blue]},
PlotRange -> {{308, 342}, {0, 0.5}}];
h3 = Histogram[x3, 6, "Probability",
ChartLegends -> {"\!$$\*SubscriptBox[\(x$$, $$3$$]\)"},
ChartStyle -> {Directive[Green]},
PlotRange -> {{308, 342}, {0, 0.5}}];
Export["C:\CompareHist.png", GraphicsColumn[{h1, h2, h3}]]


Of course I cannot use save graphics into file option as there is no such option. And by the way: why Export functions always fails? Even when trying to follow tutorial. Is it some known bug?

-
Have you tried with "\\" rather than "\" in your file name ? –  b.gatessucks Apr 2 '13 at 11:16
When no C:\ it works. But how to write paths then? –  Misery Apr 2 '13 at 11:18
Have a look at FileNameJoin. –  b.gatessucks Apr 2 '13 at 11:33
@b.gatessucks: Please answer this question so I can mark it as accepted answer. –  Misery Apr 2 '13 at 13:03
The reason why the single backslash fails as a path separator is that the backslah acts as escape character in strings as in many programming languages. "\t", for instance, codes for the tab character. This means that if you want to have the literal backslash you need to escape that with the escape character, which is the backslash itself. So "\\" is the \ character. –  Sjoerd C. de Vries Apr 2 '13 at 19:12

From my experience, outputting into the desktop is quite handy. Thus, in every notebook I have one initialization cell that selects the output folder

SetDirectory["C:\\Users\\R\\Desktop"]];


Then one that allows me to simply export every plot that I output:

Export["out.png", Out[-1]];


The problem in your exporting function is that you are not setting the directory for the figure correctly. Have a look into the exporting directory information here and, if you want to avoid doing what I suggested above, use FileNameJoin (example).

EDIT: I didn't see this, but @b.gatessucks had suggested FileNameJoin before I did.

-