Git Product home page Git Product logo

scala-plotly-client's Introduction

Build Status

Plotly client

## Installation

To add the plotly client to your code, add the following lines to your build.sbt:

libraryDependencies += "co.theasi" %% "plotly" % "0.2.0"

To install the bleeding edge version, add this instead:

resolvers += "Sonatype OSS Snapshots" at "https://oss.sonatype.org/content/repositories/snapshots"

libraryDependencies += "co.theasi" %% "plotly" % "0.2.1-SNAPSHOT"

Documentation

## Authentication

To create a graph on Plotly, start by opening an account with the web UI. Then create an API key by clicking on your username in the top right hand corner of the screen and selecting SETTINGS > API KEYS. Create the file ~/.plotly/.credentials in your home directory. The file should look like:

{
  "username": "pbugnion",
  "api_key": "l233fgfdsjk"
}

Note that if you have already used another Plotly client, you probably do not need to do this.

## Your first graph

To create a graph on the Plotly servers, start by importing the client:

import co.theasi.plotly._

Then, just pass the x, y series that you want to plot:

scala> val x = Vector(1.0, 2.0, 3.0)

scala> val y = Vector(1.0, 4.0, 9.0)

scala> val p = Plot().withScatter(x, y)

scala> draw(p, "hello-plotly")
PlotFile = PlotFile(pbugnion:264,hello-plotly)

This will create a graph called hello-plotly in your account!

## Using custom credentials

Sometimes, creating a ~/.plotly/.credentials file isn't practical. In that case, you can pass credentials to Plotly programatically by defining a custom server.

import co.theasi.plotly._

implicit val server = new writer.Server {
  val credentials = writer.Credentials("<username>", "<api_key>")
  val url = "https://api.plot.ly/v2/"
}

You can then use Plotly commands normally:

scala> val p = Plot().withScatter(Vector(1, 2, 3), Vector(1, 4, 9))

scala> draw(p, "custom-credentials")
PlotFile = PlotFile(pbugnion:268,custom-credentials)

scala-plotly-client's People

Contributors

landlockedsurfer avatar nickrobinson251 avatar pbugnion avatar srstevenson avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

scala-plotly-client's Issues

Map plots

It would be nice to be able to reproduce some of the map plots on here.

Grid manipulation

Most of the functionality so far concentrates on plotting. It would be useful to add functionality to manipulate grids.

Exception drawing ThreeDPlot

When trying to create a surface plot following the ThreeDPlot documentation, draw throws an IllegalArgumentException for me:

scala> val xs = Vector(-1.0, 0.0, 1.0)
xs: scala.collection.immutable.Vector[Double] = Vector(-1.0, 0.0, 1.0)

scala> val ys = Vector(0.0, 10.0)
ys: scala.collection.immutable.Vector[Double] = Vector(0.0, 10.0)

scala> val zs = Vector(Vector(1.0, 2.0, 1.0), Vector(5,0, 4.0, 5.0))
zs: scala.collection.immutable.Vector[scala.collection.immutable.Vector[Double]] = Vector(Vector(1.0, 2.0, 1.0), Vector(5.0, 0.0, 4.0, 5.0))

scala> val p = ThreeDPlot().withSurface(xs, ys, zs)
p: co.theasi.plotly.ThreeDPlot = ThreeDPlot(Vector(SurfaceXYZ(Vector(PDouble(-1.0), PDouble(0.0), PDouble(1.0)),Vector(PDouble(0.0), PDouble(10.0)),Vector(Vector(PDouble(1.0), PDouble(2.0), PDouble(1.0)), Vector(PDouble(5.0), PDouble(0.0), PDouble(4.0), PDouble(5.0))),SurfaceOptions(None,None,None,None))),ThreeDPlotOptions(AxisOptions(None,None,None,None,None,None,None,Font(None,None,None),Font(None,None,None),None,None,None,None),AxisOptions(None,None,None,None,None,None,None,Font(None,None,None),Font(None,None,None),None,None,None,None),AxisOptions(None,None,None,None,None,None,None,Font(None,None,None),Font(None,None,None),None,None,None,None)))

scala> draw(p, "foo")
java.lang.IllegalArgumentException: transpose requires all collections have the same size
  at scala.collection.generic.GenericTraversableTemplate$class.fail$1(GenericTraversableTemplate.scala:213)
  at scala.collection.generic.GenericTraversableTemplate$$anonfun$transpose$1$$anonfun$apply$1.apply(GenericTraversableTemplate.scala:220)
  at scala.collection.generic.GenericTraversableTemplate$$anonfun$transpose$1$$anonfun$apply$1.apply(GenericTraversableTemplate.scala:219)
  at scala.collection.immutable.List.foreach(List.scala:381)
  at scala.collection.generic.GenericTraversableTemplate$$anonfun$transpose$1.apply(GenericTraversableTemplate.scala:219)
  at scala.collection.generic.GenericTraversableTemplate$$anonfun$transpose$1.apply(GenericTraversableTemplate.scala:217)
  at scala.collection.immutable.List.foreach(List.scala:381)
  at scala.collection.generic.GenericTraversableTemplate$class.transpose(GenericTraversableTemplate.scala:217)
  at scala.collection.AbstractTraversable.transpose(Traversable.scala:104)
  at co.theasi.plotly.writer.FigureWriter$.co$theasi$plotly$writer$FigureWriter$$seriesToColumns(FigureWriter.scala:99)
  at co.theasi.plotly.writer.FigureWriter$$anonfun$10.apply(FigureWriter.scala:73)
  at co.theasi.plotly.writer.FigureWriter$$anonfun$10.apply(FigureWriter.scala:72)
  at scala.collection.TraversableLike$$anonfun$flatMap$1.apply(TraversableLike.scala:241)
  at scala.collection.TraversableLike$$anonfun$flatMap$1.apply(TraversableLike.scala:241)
  at scala.collection.Iterator$class.foreach(Iterator.scala:893)
  at scala.collection.AbstractIterator.foreach(Iterator.scala:1336)
  at scala.collection.IterableLike$class.foreach(IterableLike.scala:72)
  at scala.collection.AbstractIterable.foreach(Iterable.scala:54)
  at scala.collection.TraversableLike$class.flatMap(TraversableLike.scala:241)
  at scala.collection.AbstractTraversable.flatMap(Traversable.scala:104)
  at co.theasi.plotly.writer.FigureWriter$.drawGrid(FigureWriter.scala:72)
  at co.theasi.plotly.writer.FigureWriter$.draw(FigureWriter.scala:19)
  at co.theasi.plotly.writer.ServerWriter$class.draw(ServerWriter.scala:26)
  at co.theasi.plotly.package$.draw(package.scala:34)
  at co.theasi.plotly.writer.ServerWriter$class.draw(ServerWriter.scala:44)
  at co.theasi.plotly.package$.draw(package.scala:34)
  at co.theasi.plotly.writer.ServerWriter$class.draw(ServerWriter.scala:34)
  at co.theasi.plotly.package$.draw(package.scala:34)
  ... 42 elided

This is using master at cbdd2a7.

Is this still maintained?

The last commit was two years ago and scala 2.13.1 has been released. Will there be support for that? thanks

Custom colorscales

Plotly supports sending custom colorscales as well as the predefined ones. It might be nice to try and support that.

For instance, the following request body to the Plotly API seems to do what we expect (POST https://api.plot.ly/v2/plots ; you need to set the headers Plotly-Client-Platform to something (eg. scala), Content-Type to application/json and use basic auth with your username and password):

{
   "figure":{
      "data":[
         {
            "zsrc":"pbugnion:452:0049bf,2b5279,47daf1,964c04,6841d3,961eab",
            "type":"heatmap",
            "colorscale":[
               [
                  7,
                  "rgb(165,0,38)"
               ],
               [
                  7.1111111111111111,
                  "rgb(215,48,39)"
               ],
               [
                  7.2222222222222222,
                  "rgb(244,109,67)"
               ],
               [
                  7.3333333333333333,
                  "rgb(253,174,97)"
               ],
               [
                  8.4444444444444444,
                  "rgb(254,224,144)"
               ],
               [
                  8.5555555555555556,
                  "rgb(224,243,248)"
               ],
               [
                  8.6666666666666666,
                  "rgb(171,217,233)"
               ],
               [
                  8.7777777777777778,
                  "rgb(116,173,209)"
               ],
               [
                  8.8888888888888888,
                  "rgb(69,117,180)"
               ],
               [
                  9,
                  "rgb(49,54,149)"
               ]
            ]
         }
      ]},
   "world_readable":true
}

The colorscale field seems to be an array of 2-arrays containing a z-value and a color.

I think the following interface would work:

// current interface in, eg. contour plots
val p = ThreeDPlot().withSurface(zs, SurfaceOptions().colorscale("Viridis"))

// extensions
val customColorscale = Coloscale.fromIterable(
 List(7 -> Color.rgb(255, 0, 0), 7.5 -> Color.rgb(128, 128, 0), 8.0 -> Color.rgb(0, 255, 0))
)
val p = ThreeDPlot().withSurface(zs, SurfaceOptions().colorscale(customColorscale))

val customColorscale = Coloscale.fromFunction { z => 
  if (z < 10.0) { Color.rgb(255, 0, 0) } else { Color.rgb(0, 255, 0) }
}
val p = ThreeDPlot().withSurface(zs, SurfaceOptions().colorscale(customColorscale))

java.lang.NoSuchMethodError issue

Hi, I am getting this error when I tried to run the sample in your readme file.

"Exception in thread "main" java.lang.NoSuchMethodError: co.theasi.plotly.writer.Server.$init$(Lco/theasi/plotly/writer/Server;)V"

Platform: Windows 10
Scala version: Scala 2.10

Does scala plotly client work in Windows?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.