04. Histogram 2D

  9 import numpy as np
 10 import plotly.graph_objects as go
 11
 12 from plotly.io import show
 13
 14 try:
 15     __file__
 16     TERMINAL = True
 17 except:
 18     TERMINAL = False
 19
 20 # ----------------
 21 # Create data
 22 # ----------------
 23 t = np.linspace(-1, 1.2, 2000)
 24 x = (t**3) + (0.3 * np.random.randn(2000))
 25 y = (t**6) + (0.3 * np.random.randn(2000))
 26
 27 # ----------------
 28 # Create figure
 29 # ----------------
 30 fig = go.Figure()
 31 fig.add_trace(go.Histogram2dContour(
 32         x = x,
 33         y = y,
 34         colorscale = 'Blues', # 'Jet'
 35         contours = dict(
 36             showlabels = True,
 37             labelfont = dict(
 38                 family = 'Raleway',
 39                 color ='white'
 40             )
 41         ),
 42         hoverlabel = dict(
 43             bgcolor = 'white',
 44             bordercolor = 'black',
 45             font = dict(
 46                 family = 'Raleway',
 47                 color = 'black'
 48             )
 49         ),
 50         reversescale = True,
 51         xaxis = 'x',
 52         yaxis = 'y'
 53     ))
 54 fig.add_trace(go.Scatter(
 55         x = x,
 56         y = y,
 57         xaxis = 'x',
 58         yaxis = 'y',
 59         mode = 'markers',
 60         marker = dict(
 61             color = 'rgba(0,0,0,0.3)',
 62             size = 3
 63         )
 64     ))
 65 fig.add_trace(go.Histogram(
 66         y = y,
 67         xaxis = 'x2',
 68         marker = dict(
 69             color = 'rgba(0,0,0,1)'
 70         )
 71     ))
 72 fig.add_trace(go.Histogram(
 73         x = x,
 74         yaxis = 'y2',
 75         marker = dict(
 76             color = 'rgba(0,0,0,1)'
 77         )
 78     ))
 79
 80 fig.update_layout(
 81     autosize = False,
 82     xaxis = dict(
 83         zeroline = False,
 84         domain = [0,0.85],
 85         showgrid = False
 86     ),
 87     yaxis = dict(
 88         zeroline = False,
 89         domain = [0,0.85],
 90         showgrid = False
 91     ),
 92     xaxis2 = dict(
 93         zeroline = False,
 94         domain = [0.85,1],
 95         showgrid = False
 96     ),
 97     yaxis2 = dict(
 98         zeroline = False,
 99         domain = [0.85,1],
100         showgrid = False
101     ),
102     height = 600,
103     width = 600,
104     bargap = 0,
105     hovermode = 'closest',
106     showlegend = False
107 )
108
109 # Show
110 show(fig)

Total running time of the script: ( 0 minutes 0.472 seconds)

Gallery generated by Sphinx-Gallery