Group Abstract Group Abstract

Message Boards Message Boards

Why a Histogram is not returned properly as image with CloudDeploy?

POSTED BY: Balazs Kisfali
4 Replies
Posted 8 years ago
POSTED BY: Simon Johnston

Some things you probably want to know.

Plotting functions do not actually return images. They output some code. This code is then interpreted by the front end as a graphic that you can see. That is, it returns a kind of vector graphic, like SVG which more people are familiar with.

You can see what the underlying code for a graphic looks like by wrapping it in the function "InputForm".

POSTED BY: Sean Clarke

Short Answer:

You have to tell APIFunction or whatever you are using to make an Image by specifying what format it should be. Take a look at this code from the documentation:

CloudDeploy[
 APIFunction["country" -> "Country", 
  GeoGraphics[Polygon[#country]] &, "PNG"]]

The last argument to APIFunction is "PNG", telling it to render the output as a PNG.

POSTED BY: Sean Clarke

Hi Sean, Thanks for your answer. Actually I am doing on that way, so the argument is "PNG" Please see the whole code below.

myDist[Latitude_, Longitude_] := 
 EstimatedDistribution[
  WeatherData[{Latitude, Longitude}, 
   "MaxWindSpeed", {{1990}, {2015}, "Year"}], 
  GumbelDistribution[\[Alpha], \[Beta]], 
  ParameterEstimator -> "MaximumLikelihood", WorkingPrecision -> 25]

CloudDeploy[
 APIFunction[{"Latitude" -> "Integer", "Longitude" -> "Integer"}, 
  Show[Histogram[
     WeatherData[{#Latitude, #Longitude}, 
      "MaxWindSpeed", {{1990}, {2015}, "Year"}], 6, 
     "ProbabilityDensity", ChartStyle -> "Aquamarine", 
     PlotRange -> All], 
    Plot[PDF[myDist[{#Latitude, #Longitude}], 
       Quantity[x, "Kilometers"/"Hours"]] // Evaluate, {x, 0, 200}, 
     PlotRange -> {Automatic, All}, 
     PlotStyle -> {Blend[{Blue, Black}], Thick}]] &, "PNG"], 
 Permissions -> "Public"]

However, it doesn't work properly. In some calls is ok but if I call again then the above result can be seen. Can be something with the function itself? What is also strange that in Mathematica notebook has similar output sometimes, after evaluate notebook.

I copy the link here below from the above code. I made it public, so you can test it yourself as well. (at the moment it works with integers) https://www.wolframcloud.com/objects/5cc0a503-f381-4120-af24-89d4282989f9

POSTED BY: Balazs Kisfali
Reply to this discussion
Community posts can be styled and formatted using the Markdown syntax.
Reply Preview
Attachments
Remove
or Discard