Skip to content

Can we set the image size in pixels? #93

Open

Description

@hmf

I would like to set the image size in pixels.
I tried this but it does not work.

    val bufferedImage = plot
      .xAxis()
      .yAxis()
      .frame()
      .xLabel("x")
      .yLabel("y")
      .render(Extent(800, 600))
      .asBufferedImage
    ImageIO.write(bufferedImage, "png", file1)

Is this the correct way to do it?

Activity

  1. hmf commented on Sep 10, 2019

    @hmf
    Author

    As an update, I looked at the code and cheated by using .render(Extent(800/4, 600/4)). So the image size is sort of ok (853 x 600) but the scaling is off. I get the image below:

    e2fd9677-263d-45b9-aae3-09f9a8168450_evilplot

    So Extent seems to be for image size, but something seems to be wrong.

    BTW, using version 0.7.0

    Full code below:

    
        import com.cibo.evilplot._
        import com.cibo.evilplot.plot._
        import com.cibo.evilplot.plot.aesthetics.DefaultTheme._
        import com.cibo.evilplot.numeric.Point
        import com.cibo.evilplot.geometry.Extent
    
        import better.files._
        import File._
        import java.io.{File => JFile}
        import javax.imageio.ImageIO
    
        val data = Seq.tabulate(100) { i =>
          Point(i.toDouble, scala.util.Random.nextDouble())
        }
    
        val plot = ScatterPlot(data)
    
        // Supported out of the box: JPEG, PNG, GIF, BMP and WBMP
        val property = "java.io.tmpdir"
        val tempDir = System.getProperty(property)
        val file1 = Utils.temporaryFile(tempDir, "_evilplot.png").toJava
        val bufferedImage = plot
          .xAxis()
          .yAxis()
          .frame()
          .xLabel("x")
          .yLabel("y")
          .render(Extent(800/4, 600/4))
          .asBufferedImage
        ImageIO.write(bufferedImage, "png", file1)
    
        file1.getPath
    
    
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions