googlefonts / fontelemetry

A library and toolset for typeface software development reporting
Apache License 2.0
2 stars 3 forks source link

Heatmaps with Plotly (Python) #4

Open chrissimpkins opened 5 years ago

chrissimpkins commented 5 years ago

Source: https://plot.ly/~chrissimpkins/3/

Documentation: https://plot.ly/python/reference/#heatmap

Image

39q3d-image

Example Python source with Plotly library:

# Get this figure: fig = py.get_figure("https://plot.ly/~chrissimpkins/3/")
# Get this figure's data: data = py.get_figure("https://plot.ly/~chrissimpkins/3/").get_data()
# Add data to this figure: py.plot(Data([Scatter(x=[1, 2], y=[2, 3])]), filename ="Plot 3", fileopt="extend")
# Get y data of first trace: y1 = py.get_figure("https://plot.ly/~chrissimpkins/3/").get_data()[0]["y"]

# Get figure documentation: https://plot.ly/python/get-requests/
# Add data documentation: https://plot.ly/python/file-options/

# If you're using unicode in your file, you may need to specify the encoding.
# You can reproduce this figure in Python with the following code!

# Learn about API authentication here: https://plot.ly/python/getting-started
# Find your api_key here: https://plot.ly/settings/api

import plotly.plotly as py
from plotly.graph_objs import *
py.sign_in('username', 'api_key')
trace1 = {
  "x": ["01", "02", "03", "04", "05", "06", "07", "2017-03-27 18:41:17.237927", "2017-03-26 18:41:17.237927", "2017-03-25 18:41:17.237927", "2017-03-24 18:41:17.237927", "2017-03-23 18:41:17.237927", "2017-03-22 18:41:17.237927", "2017-03-21 18:41:17.237927", "2017-03-20 18:41:17.237927", "2017-03-19 18:41:17.237927", "2017-03-18 18:41:17.237927", "2017-03-17 18:41:17.237927", "2017-03-16 18:41:17.237927", "2017-03-15 18:41:17.237927", "2017-03-14 18:41:17.237927", "2017-03-13 18:41:17.237927", "2017-03-12 18:41:17.237927", "2017-03-11 18:41:17.237927", "2017-03-10 18:41:17.237927", "2017-03-09 18:41:17.237927", "2017-03-08 18:41:17.237927", "2017-03-07 18:41:17.237927", "2017-03-06 18:41:17.237927", "2017-03-05 18:41:17.237927", "2017-03-04 18:41:17.237927", "2017-03-03 18:41:17.237927", "2017-03-02 18:41:17.237927", "2017-03-01 18:41:17.237927", "2017-02-28 18:41:17.237927", "2017-02-27 18:41:17.237927", "2017-02-26 18:41:17.237927", "2017-02-25 18:41:17.237927", "2017-02-24 18:41:17.237927", "2017-02-23 18:41:17.237927", "2017-02-22 18:41:17.237927", "2017-02-21 18:41:17.237927", "2017-02-20 18:41:17.237927", "2017-02-19 18:41:17.237927", "2017-02-18 18:41:17.237927", "2017-02-17 18:41:17.237927", "2017-02-16 18:41:17.237927", "2017-02-15 18:41:17.237927", "2017-02-14 18:41:17.237927", "2017-02-13 18:41:17.237927", "2017-02-12 18:41:17.237927", "2017-02-11 18:41:17.237927", "2017-02-10 18:41:17.237927", "2017-02-09 18:41:17.237927", "2017-02-08 18:41:17.237927", "2017-02-07 18:41:17.237927", "2017-02-06 18:41:17.237927", "2017-02-05 18:41:17.237927", "2017-02-04 18:41:17.237927", "2017-02-03 18:41:17.237927", "2017-02-02 18:41:17.237927", "2017-02-01 18:41:17.237927", "2017-01-31 18:41:17.237927", "2017-01-30 18:41:17.237927", "2017-01-29 18:41:17.237927", "2017-01-28 18:41:17.237927", "2017-01-27 18:41:17.237927", "2017-01-26 18:41:17.237927", "2017-01-25 18:41:17.237927", "2017-01-24 18:41:17.237927", "2017-01-23 18:41:17.237927", "2017-01-22 18:41:17.237927", "2017-01-21 18:41:17.237927", "2017-01-20 18:41:17.237927", "2017-01-19 18:41:17.237927", "2017-01-18 18:41:17.237927", "2017-01-17 18:41:17.237927", "2017-01-16 18:41:17.237927", "2017-01-15 18:41:17.237927", "2017-01-14 18:41:17.237927", "2017-01-13 18:41:17.237927", "2017-01-12 18:41:17.237927", "2017-01-11 18:41:17.237927", "2017-01-10 18:41:17.237927", "2017-01-09 18:41:17.237927", "2017-01-08 18:41:17.237927", "2017-01-07 18:41:17.237927", "2017-01-06 18:41:17.237927", "2017-01-05 18:41:17.237927", "2017-01-04 18:41:17.237927", "2017-01-03 18:41:17.237927", "2017-01-02 18:41:17.237927", "2017-01-01 18:41:17.237927", "2016-12-31 18:41:17.237927", "2016-12-30 18:41:17.237927", "2016-12-29 18:41:17.237927", "2016-12-28 18:41:17.237927", "2016-12-27 18:41:17.237927", "2016-12-26 18:41:17.237927", "2016-12-25 18:41:17.237927", "2016-12-24 18:41:17.237927", "2016-12-23 18:41:17.237927", "2016-12-22 18:41:17.237927", "2016-12-21 18:41:17.237927", "2016-12-20 18:41:17.237927", "2016-12-19 18:41:17.237927", "2016-12-18 18:41:17.237927", "2016-12-17 18:41:17.237927", "2016-12-16 18:41:17.237927", "2016-12-15 18:41:17.237927", "2016-12-14 18:41:17.237927", "2016-12-13 18:41:17.237927", "2016-12-12 18:41:17.237927", "2016-12-11 18:41:17.237927", "2016-12-10 18:41:17.237927", "2016-12-09 18:41:17.237927", "2016-12-08 18:41:17.237927", "2016-12-07 18:41:17.237927", "2016-12-06 18:41:17.237927", "2016-12-05 18:41:17.237927", "2016-12-04 18:41:17.237927", "2016-12-03 18:41:17.237927", "2016-12-02 18:41:17.237927", "2016-12-01 18:41:17.237927", "2016-11-30 18:41:17.237927", "2016-11-29 18:41:17.237927", "2016-11-28 18:41:17.237927", "2016-11-27 18:41:17.237927", "2016-11-26 18:41:17.237927", "2016-11-25 18:41:17.237927", "2016-11-24 18:41:17.237927", "2016-11-23 18:41:17.237927", "2016-11-22 18:41:17.237927", "2016-11-21 18:41:17.237927", "2016-11-20 18:41:17.237927", "2016-11-19 18:41:17.237927", "2016-11-18 18:41:17.237927", "2016-11-17 18:41:17.237927", "2016-11-16 18:41:17.237927", "2016-11-15 18:41:17.237927", "2016-11-14 18:41:17.237927", "2016-11-13 18:41:17.237927", "2016-11-12 18:41:17.237927", "2016-11-11 18:41:17.237927", "2016-11-10 18:41:17.237927", "2016-11-09 18:41:17.237927", "2016-11-08 18:41:17.237927", "2016-11-07 18:41:17.237927", "2016-11-06 18:41:17.237927", "2016-11-05 18:41:17.237927", "2016-11-04 18:41:17.237927", "2016-11-03 18:41:17.237927", "2016-11-02 18:41:17.237927", "2016-11-01 18:41:17.237927", "2016-10-31 18:41:17.237927", "2016-10-30 18:41:17.237927", "2016-10-29 18:41:17.237927", "2016-10-28 18:41:17.237927", "2016-10-27 18:41:17.237927", "2016-10-26 18:41:17.237927", "2016-10-25 18:41:17.237927", "2016-10-24 18:41:17.237927", "2016-10-23 18:41:17.237927", "2016-10-22 18:41:17.237927", "2016-10-21 18:41:17.237927", "2016-10-20 18:41:17.237927", "2016-10-19 18:41:17.237927", "2016-10-18 18:41:17.237927", "2016-10-17 18:41:17.237927", "2016-10-16 18:41:17.237927", "2016-10-15 18:41:17.237927", "2016-10-14 18:41:17.237927", "2016-10-13 18:41:17.237927", "2016-10-12 18:41:17.237927", "2016-10-11 18:41:17.237927", "2016-10-10 18:41:17.237927", "2016-10-09 18:41:17.237927", "2016-10-08 18:41:17.237927", "2016-10-07 18:41:17.237927", "2016-10-06 18:41:17.237927"], 
  "y": ["Range 1", "Range 2", "Range 3", "Range 4", "Range 5", "Range 6", "Range 7"], 
  "z": [
    [2, 4, 0, 2, 3, 0, 0, 0, 3, 4, 3, 1, 2, 0, 0, 0, 1, 1, 2, 1, 0, 2, 1, 2, 2, 1, 2, 3, 2, 0, 2, 0, 2, 2, 2, 0, 0, 1, 2, 1, 1, 2, 1, 1, 4, 1, 1, 2, 3, 0, 1, 1, 0, 2, 1, 2, 2, 0, 3, 2, 1, 2, 3, 1, 3, 0, 1, 1, 0, 2, 0, 1, 1, 1, 2, 2, 1, 0, 0, 1, 0, 1, 2, 0, 2, 1, 1, 1, 1, 1, 2, 2, 1, 1, 0, 3, 0, 0, 1, 1, 2, 2, 1, 0, 1, 0, 1, 0, 1, 0, 1, 1, 0, 2, 0, 0, 2, 1, 2, 2, 1, 1, 1, 1, 0, 1, 1, 2, 2, 1, 1, 0, 1, 0, 1, 0, 0, 0, 4, 0, 1, 2, 3, 1, 1, 0, 1, 1, 1, 0, 2, 1, 2, 1, 0, 0, 0, 1, 1, 1, 0, 1, 1, 1, 0, 0, 1, 3, 1, 0, 0, 0, 3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, 1, 1, 1, 0, 1, 1, 0, 1, 0, 2, 2, 0, 4, 2, 0, 1, 1, 1, 0, 2, 0, 0, 1, 1, 1, 0, 2, 1, 2, 0, 2, 0, 0, 1, 0, 2, 1, 0, 0, 0, 0, 0, 2, 3, 0, 0, 0, 0, 1, 0, 1, 1, 2, 1, 0, 0, 1, 0, 4, 1, 0, 1, ], 
  "colorscale": "Viridis", 
  "type": "heatmap", 
  "xsrc": "chrissimpkins:2:c6860c", 
  "ysrc": "chrissimpkins:2:c9013a", 
  "zsrc": "chrissimpkins:2:-c6860c,c9013a"
}
data = Data([trace1])
layout = {
  "title": {"text": "Glyph Heatmap"}, 
  "xaxis": {
    "autorange": True, 
    "nticks": 36, 
    "range": [-0.5, 179.5], 
    "showticklabels": False, 
    "ticks": "", 
    "type": "category"
  }, 
  "yaxis": {
    "autorange": True, 
    "range": [-0.5, 6.5], 
    "ticks": "", 
    "type": "category"
  }
}
fig = Figure(data=data, layout=layout)
plot_url = py.plot(fig)
chrissimpkins commented 5 years ago

Colorscale can be set with the colorscale property using RGBA format that is pulled directly from glyph highlight color scheme or mapped to a different RGBA scheme from that color scheme:

colorscale (colorscale) Sets the colorscale. The colorscale must be an array containing arrays mapping a normalized value to an rgb, rgba, hex, hsl, hsv, or named color string. At minimum, a mapping for the lowest (0) and highest (1) values are required. For example, [[0, 'rgb(0,0,255)', [1, 'rgb(255,0,0)']]. To control the bounds of the colorscale in color space, usezmin and zmax. Alternatively, colorscale may be a palette name string of the following list: Greys,YlGnBu,Greens,YlOrRd,Bluered,RdBu,Reds,Blues,Picnic,Rainbow,Portland,Jet,Hot,Blackbody,Earth,Electric,Viridis,Cividis