Why do BarChart graphics exported from Mathematica have pixelated text? Is there a workaround?

孤街醉人 提交于 2019-11-30 15:23:10

UPDATE

Many years later, Wolfram came back with a fix.

Export[stringtouse, 
     DeleteCases[ obj /. {_Opacity, p_Point} :> 
     {PointSize[0], p}, _Opacity, Infinity], opts]

I bound this up into a little helper function like this.

ExportEMFNicely[pathorfile_String, obj_, opts:OptionsPattern[{Export}]]:=
With[{stringtouse = If[ToLowerCase[StringTake[pathorfile,-4]]===".emf", 
 pathorfile, pathorfile<>".emf"]},
Export[stringtouse, 
 DeleteCases[ obj /. {_Opacity, p_Point} :> 
  {PointSize[0], p}, _Opacity, Infinity], opts] ]

This produces vector EMFs without any need to Magnify or use ImageResolution hacks.

ORIGINAL ANSWER

Wolfram support got back to me. Short answer is that it is a bug in Mathematica and they recommend either using another format or Rasterize

Thank you for your email. Issues relating to the quality of exported images from Mathematica have been reported in the past and our developers are looking into these. I have however filed a separate report on your behalf. I have also included your contact information so you can be notified when this is resolved.

In the meantime, the other option that you can try is to rasterize the graphic with an appropriate resolution before exporting to EMF.

Rasterize[graphic, ImageResolution-> XXX]

You could also try exporting to other Windows formats like RTF.

EDIT

I have since worked out that you can work around this issue (at least in v 8.0.4 and v 9.0.1) using a very high value for ImageResolution in the Export command.

bc = BarChart[RandomInteger[{1, 20}, {15}], Frame -> True, 
  FrameStyle -> AbsoluteThickness[1], PlotRangePadding -> 0, 
  PlotRange -> {0, 20}, 
  BaseStyle -> {FontFamily -> "Arial", FontSize -> 16}, 
  LabelingFunction -> None]

Export["testbarchart.emf", bc, ImageResolution -> 2000]

Setting ImageResolution to 1300 or higher results in vector-format text and a 50k EMF file. However setting it to 1000 results in a high-resolution raster taking up 48 Mb! This behaviour is, as far as I know, undocumented. It also seems to create problems with tick marks, in that they only show up if you explicitly set their lengths using the more complex syntax for Ticks, FrameTicks etc (see documentation.)

One caveat to this fix is that Mathematica still thinks that it needs as much memory to create this smaller, vector-based EMF file as it would to create the high-resolution bitmap. So it will sometimes complain about not having enough memory and you will need to quit out of some other applications. It doesn't actually need all that memory to create the vector EMF. In my experiments, anything 1300 or above will work to trigger the vector export, while 1200 and below will generate a high-resolution, enormous bitmap.

Alexey Popkov

I think you can find useful my Toolbag answer: "General PDF/EMF export problems and solutons." And this answer is also strongly relevant (try cyrFix function).

What version of Mma are you using?

In v8:

a =  BarChart[{1, 2, 3}]
Export["c:\\test.pdf", a]

And zooming into the pdf:

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!