.. DO NOT EDIT. .. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY. .. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE: .. "_examples/plotly/plot_main04_2dhist.py" .. LINE NUMBERS ARE GIVEN BELOW. .. only:: html .. note:: :class: sphx-glr-download-link-note Click :ref:`here ` to download the full example code .. rst-class:: sphx-glr-example-title .. _sphx_glr__examples_plotly_plot_main04_2dhist.py: 04. Histogram 2D ====================== .. note:: https://plotly.com/python/2d-histogram-contour/ .. GENERATED FROM PYTHON SOURCE LINES 8-110 .. raw:: html :file: images/sphx_glr_plot_main04_2dhist_001.html .. code-block:: default :lineno-start: 9 import numpy as np import plotly.graph_objects as go from plotly.io import show try: __file__ TERMINAL = True except: TERMINAL = False # ---------------- # Create data # ---------------- t = np.linspace(-1, 1.2, 2000) x = (t**3) + (0.3 * np.random.randn(2000)) y = (t**6) + (0.3 * np.random.randn(2000)) # ---------------- # Create figure # ---------------- fig = go.Figure() fig.add_trace(go.Histogram2dContour( x = x, y = y, colorscale = 'Blues', # 'Jet' contours = dict( showlabels = True, labelfont = dict( family = 'Raleway', color ='white' ) ), hoverlabel = dict( bgcolor = 'white', bordercolor = 'black', font = dict( family = 'Raleway', color = 'black' ) ), reversescale = True, xaxis = 'x', yaxis = 'y' )) fig.add_trace(go.Scatter( x = x, y = y, xaxis = 'x', yaxis = 'y', mode = 'markers', marker = dict( color = 'rgba(0,0,0,0.3)', size = 3 ) )) fig.add_trace(go.Histogram( y = y, xaxis = 'x2', marker = dict( color = 'rgba(0,0,0,1)' ) )) fig.add_trace(go.Histogram( x = x, yaxis = 'y2', marker = dict( color = 'rgba(0,0,0,1)' ) )) fig.update_layout( autosize = False, xaxis = dict( zeroline = False, domain = [0,0.85], showgrid = False ), yaxis = dict( zeroline = False, domain = [0,0.85], showgrid = False ), xaxis2 = dict( zeroline = False, domain = [0.85,1], showgrid = False ), yaxis2 = dict( zeroline = False, domain = [0.85,1], showgrid = False ), height = 600, width = 600, bargap = 0, hovermode = 'closest', showlegend = False ) # Show show(fig) .. rst-class:: sphx-glr-timing **Total running time of the script:** ( 0 minutes 0.472 seconds) .. _sphx_glr_download__examples_plotly_plot_main04_2dhist.py: .. only :: html .. container:: sphx-glr-footer :class: sphx-glr-footer-example .. container:: sphx-glr-download sphx-glr-download-python :download:`Download Python source code: plot_main04_2dhist.py ` .. container:: sphx-glr-download sphx-glr-download-jupyter :download:`Download Jupyter notebook: plot_main04_2dhist.ipynb ` .. only:: html .. rst-class:: sphx-glr-signature `Gallery generated by Sphinx-Gallery `_