JuliaPlots / Plots.jl

Powerful convenience for Julia visualizations and data analysis
https://docs.juliaplots.org
Other
1.84k stars 354 forks source link

GR: Missing output MIMEs #649

Open ma-laforge opened 7 years ago

ma-laforge commented 7 years ago

I noticed the GR backend does not support either EPS or CGM output.

EPS I found EPS images are often easier to integrate in a document than PS.

CGM I thought CGM was GR's native output.

IMO, CGM support is one of GR's key assets: I found that many applications have still have better support for CGM than SVG (even Microsoft apps seem to support CGM as well as their own WMF/EMF formats).

In fact, CGMs typically render with full quality within MS apps whereas EPS/SVG often either display using poor bitmapped previews (or simply white boxes) until printed.

@jheinen: Is adding support for EPS & CGM not trivial for GR?

jheinen commented 7 years ago

EPS is fully supported:

using GR
beginprint("ex.eps")
histogram(randn(10000), title="\$\\textrm{Histogram : }\\sigma = \\sqrt {\\mu_2 }\$")
endprint()

I could provide support for CGM, too - it's already supported by the underlying GKS. But currently I have no chance to check the output as I have no CGM viewer.

You can create CGM by setting the GKS_WSTYPE environment to "cgm" and run your script. This will produce a file gks.cgm (in clear-text format). However, this output driver has not been tested for years.

ma-laforge commented 7 years ago

The above EPS example works for me, but the output was actually the same as the PostScript output.

Is this normal? Is the only difference between the two that EPS must have a BoundingBox statement (whereas it is optional for PS)?

ma-laforge commented 7 years ago

I tried integrating into Plots.jl:

I added to _gr_mimeformats::Dict

    "image/eps"               => "eps",

Then tried running the following:

using Plots; gr()
histogram(randn(10000), title="\$Histogram : \\sigma = \\sqrt {\\mu_2 }\$")
Plots.eps("nan.eps")

I get an error, because Plots.jl looks for a file in /tmp with an extension .eps... but gr creates the file with extension .ps instead.

jheinen commented 7 years ago

GR's PostScript output conforms to the EPS specification (relative coordinates, BoundingBox, dict, etc.). It is enough to alias the showpage operator when encapsulating GR PostScript, which is normally done at a higher level.

ChasingZenith commented 3 years ago
using Plots
gr()
plot(sin)
savefig("sin.png") # works for me
savefig("sin.eps") # do not work for me

need helps too