New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Headless Plotting #74
Comments
Try this val window = plot(data) |
That also throws the same exception. I'm guessing because the window hasn't really opened 'fully' and the width/height of the plot canvas still thinks it's zero. |
I see. Maybe we need to add new interface for your use case. |
As a quick work around, you may pause a little bit before calling save, which make sure the window is properly initialized. |
Read your first message again. Do you mean #2 approach works? Thanks! |
No it just results in a solid image of the color as if |
What platform do you use? |
|
Can you try approach 2 on windows? Swing has al it of issues on Linux and Mac. Thanks! |
Would be happy to except I don't have access to a Window machine. |
Have you tried pausing a little bit before save? |
Any updates? Did you try pause a little bit. |
Ah. Sorry about that. I've haven't had time to try it out. I suspect it will work when I get a chance but it's not really a viable option in my specific use case since I was generating 100's of plots. Introducing even a small delay (i.e. a few seconds per plot) would be a show stopper. |
The problem is that graphics projection depends on the PlotCanvas size. Because the canvas is not materialized, nothing works as expected. If you create a multithreaded program that shows the canvas, save it, and closes automatically, I guess that it may be not too bad for your use cases. |
I think the correct solution for this is to use Graphics2D implementation For example of non-standard Graphics2D implementation, see e.g. this one: Specifically check out this example of headless painting: On Thu, Apr 7, 2016 at 3:52 PM, Haifeng Li notifications@github.com wrote:
|
Would you like to take the lead on fixing it? Thanks! |
@haifengl I'll think about it, so far I've checked out the code and tried to explore it a little bit. It seems like it should be doable. When I imported the code into IntelliJ IDEA there were a couple of problems, the most notable of which I guess was that SLF4J wasn't set as a dependency in pom.xml files. |
We use sbt now. Pom files will be deleted. Please install sbt plugin and import it again. |
Following @chhh suggestion, I add headless support now. You need to do a git pull and build smile by yourself to use it for now. val toy = readTable("shell/src/universal/data/classification/toy/toy-train.txt", Some((new NominalAttribute("class"), 0))) val canvas = ScatterPlot.plot(x, '.', java.awt.Color.BLACK) val headless = new Headless(canvas); canvas.save(new java.io.File("zone.png")) |
It works for me. Please let me know if it works for you too. Thanks! |
BTW, you show run JVM with option -Djava.awt.headless=true |
Is it possible to generate a plot and save it to file without needing to open a window? I'm trying to generate a few thousand plot images and I'm blocked at the moment.
[error] Exception in thread "main" java.lang.IllegalArgumentException: Width (0) and height (0) cannot be <= 0
Any help would be greatly appreciated!
The text was updated successfully, but these errors were encountered: