-
Notifications
You must be signed in to change notification settings - Fork 98
[Question] Custom maps / geojson (Choropleth maps) #86
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
Comments
Hi @luisquintanilla , thanks for the question, it sent me down quite some rabbit hole 😄 It took me quite a while, mainly due to not knowing what geojson exactly is, but i made the python example you linked work in F#. As always with un-wrapped features, you currently have to access some low level properties though. The following things are needed:
Here is a snippet.
#r "nuget: FSharp.Data"
#r "nuget: Deedle"
#r "nuget: Newtonsoft.Json"
#r "nuget: Plotly.NET, 2.0.0-preview.3"
open Plotly.NET
open GenericChart
open FSharp.Data
open Newtonsoft.Json
open System.Text
open System.IO
open Deedle
let geoJson =
Http.RequestString "https://raw.githubusercontent.com/plotly/datasets/master/geojson-counties-fips.json"
|> JsonConvert.DeserializeObject
let data =
let dataString = Http.RequestString "https://raw.githubusercontent.com/plotly/datasets/master/fips-unemp-16.csv"
let byteArray = Encoding.UTF8.GetBytes(dataString)
use stream = new MemoryStream(byteArray)
Frame.ReadCsv(stream,true,separators=",",schema="fips=string,unemp=float")
let locations: string [] =
data
|> Frame.getCol "fips"
|> Series.values
|> Array.ofSeq
let z: int [] =
data
|> Frame.getCol "unemp"
|> Series.values
|> Array.ofSeq
Trace.initChoroplethMap(id)
|> fun t ->
t?z <- z
t?locations <- locations
t?geojson <- geoJson
t?featureidkey <- "id"
t?locationmode <- "geojson-id"
t
|> GenericChart.ofTraceObject
|> Chart.withMap(
Geo.init(
Scope=StyleParam.GeoScope.Usa
)
)
|> Chart.Show To add this to Plotly.NET, basically only the featureidkey, locationmode and geojson options are missing, so this can be implemented very easily. I will add it in the next prerelease. |
Wow! Thanks @kMutagene. I was expecting a yes / no answer but you went above and beyond! Thanks so much! 😃 |
@luisquintanilla glad you liked it! It was a possibility to learn something new for me, so it was cool going down that rabbit hole. I released a new preview package that contains the relevant changes to use this with the high level abstractions contained in |
Is there a way to provide or use custom geojson with Plotly.NET?
https://plotly.com/python/choropleth-maps/#choropleth-map-using-geojson
I'm looking to focus on a specific US city / state as opposed to using the USA_States or CountryNames built in LocationFormat
The text was updated successfully, but these errors were encountered: