Mathematica Stack Exchange is a question and answer site for users of Mathematica. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

Is there a way to add a title to an X3D (3D) plot that is exported using Export[]? I didn't have much success with exporting a Text[] into an X3D file. I also know that X3D files have several properties (meta tags) that could be helpful, but I don't know how to specify them in the Export[] command.

plot = Plot3D[x^2 + y^2, {x, -2, 2}, {y, -2, 2}, PlotLabel -> "MyPlot"];
scaledPlot = plot /. Graphics3D[gr_, opts___] -> 
   Graphics3D[GeometricTransformation[gr, ScalingTransform[{1, 1, 0.5}]], opts];
Export["plot.x3d", Show[scaledPlot, Graphics3D[Text["MyPlot"]]]]
share|improve this question

I think the answer is: No, it cannot be done using Export alone. According to the documentation, there is no meta data listed in the elements available for export, nor in the options.

To accomplish what you would like to do, however, can be done via a two step process. First, save your plot as an X3D file, and the Import it as an XML file, as follows

plotxml = Import["plot.x3d", "XML"]

Then, it is just a matter of inserting your element into the XML tree. From a brief browsing of the X3D spec, I am not sure of the specific element you need to insert you data into. Likely, though, your new element will be a MetadataString, so it should look like

mdat = XMLElement["MetadataString", {"name" -> "Title", "value" -> "MyPlot", ...}, {}]

And, once you have found which element it belongs in, you can use

plotxml = plotxml /. XMLElement["ParentElement", attrs_, data_]:>
   XMLElement["ParentElement", attrs_, Append[data, mdat];

It is likely that you will have to specify the attrs list to only affect the specific element you are looking for.

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.