jupyter | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
A 2D contour plot shows the contour lines of a 2D numerical array z
, i.e. interpolated lines of isovalues of z
.
importplotly.graph_objectsasgofig=go.Figure(data=go.Contour( z=[[10, 10.625, 12.5, 15.625, 20], [5.625, 6.25, 8.125, 11.25, 15.625], [2.5, 3.125, 5., 8.125, 12.5], [0.625, 1.25, 3.125, 6.25, 10.625], [0, 0.625, 2.5, 5.625, 10]] )) fig.show()
importplotly.graph_objectsasgofig=go.Figure(data=go.Contour( z=[[10, 10.625, 12.5, 15.625, 20], [5.625, 6.25, 8.125, 11.25, 15.625], [2.5, 3.125, 5., 8.125, 12.5], [0.625, 1.25, 3.125, 6.25, 10.625], [0, 0.625, 2.5, 5.625, 10]], x=[-9, -6, -5 , -3, -1], # horizontal axisy=[0, 1, 4, 5, 7] # vertical axis )) fig.show()
importplotly.graph_objectsasgofig=go.Figure(data=go.Contour( z=[[10, 10.625, 12.5, 15.625, 20], [5.625, 6.25, 8.125, 11.25, 15.625], [2.5, 3.125, 5., 8.125, 12.5], [0.625, 1.25, 3.125, 6.25, 10.625], [0, 0.625, 2.5, 5.625, 10]], colorscale='Electric', )) fig.show()
importplotly.graph_objectsasgofig=go.Figure(data=go.Contour( z=[[10, 10.625, 12.5, 15.625, 20], [5.625, 6.25, 8.125, 11.25, 15.625], [2.5, 3.125, 5., 8.125, 12.5], [0.625, 1.25, 3.125, 6.25, 10.625], [0, 0.625, 2.5, 5.625, 10]], colorscale='Hot', contours=dict( start=0, end=8, size=2, ), )) fig.show()
importplotly.graph_objectsasgofig=go.Figure(data=go.Contour( z= [[10, 10.625, 12.5, 15.625, 20], [5.625, 6.25, 8.125, 11.25, 15.625], [2.5, 3.125, 5., 8.125, 12.5], [0.625, 1.25, 3.125, 6.25, 10.625], [0, 0.625, 2.5, 5.625, 10]], dx=10, x0=5, dy=10, y0=10, ) ) fig.show()
importplotly.graph_objsasgofromplotly.subplotsimportmake_subplotsfig=make_subplots(rows=2, cols=2, subplot_titles=('connectgaps = False', 'connectgaps = True')) z= [[None, None, None, 12, 13, 14, 15, 16], [None, 1, None, 11, None, None, None, 17], [None, 2, 6, 7, None, None, None, 18], [None, 3, None, 8, None, None, None, 19], [5, 4, 10, 9, None, None, None, 20], [None, None, None, 27, None, None, None, 21], [None, None, None, 26, 25, 24, 23, 22]] fig.add_trace(go.Contour(z=z, showscale=False), 1, 1) fig.add_trace(go.Contour(z=z, showscale=False, connectgaps=True), 1, 2) fig.add_trace(go.Heatmap(z=z, showscale=False, zsmooth='best'), 2, 1) fig.add_trace(go.Heatmap(z=z, showscale=False, connectgaps=True, zsmooth='best'), 2, 2) fig['layout']['yaxis1'].update(title=dict(text='Contour map')) fig['layout']['yaxis3'].update(title=dict(text='Heatmap')) fig.show()
importplotly.graph_objectsasgofromplotly.subplotsimportmake_subplotsimportnumpyasnpz= [[2, 4, 7, 12, 13, 14, 15, 16], [3, 1, 6, 11, 12, 13, 16, 17], [4, 2, 7, 7, 11, 14, 17, 18], [5, 3, 8, 8, 13, 15, 18, 19], [7, 4, 10, 9, 16, 18, 20, 19], [9, 10, 5, 27, 23, 21, 21, 21], [11, 14, 17, 26, 25, 24, 23, 22]] fig=make_subplots(rows=1, cols=2, subplot_titles=('Without Smoothing', 'With Smoothing')) fig.add_trace(go.Contour(z=z, line_smoothing=0), 1, 1) fig.add_trace(go.Contour(z=z, line_smoothing=0.85), 1, 2) fig.show()
importplotly.graph_objectsasgofig=go.Figure(data=go.Contour( z=[[10, 10.625, 12.5, 15.625, 20], [5.625, 6.25, 8.125, 11.25, 15.625], [2.5, 3.125, 5., 8.125, 12.5], [0.625, 1.25, 3.125, 6.25, 10.625], [0, 0.625, 2.5, 5.625, 10]], # heatmap gradient coloring is applied between each contour levelcontours_coloring='heatmap'# can also be 'lines', or 'none' ) ) fig.show()
importplotly.graph_objectsasgofig=go.Figure(data=go.Contour( z=[[10, 10.625, 12.5, 15.625, 20], [5.625, 6.25, 8.125, 11.25, 15.625], [2.5, 3.125, 5., 8.125, 12.5], [0.625, 1.25, 3.125, 6.25, 10.625], [0, 0.625, 2.5, 5.625, 10]], contours=dict( coloring='heatmap', showlabels=True, # show labels on contourslabelfont=dict( # label font propertiessize=12, color='white', ) ))) fig.show()
importplotly.graph_objectsasgofig=go.Figure(data=go.Contour( z=[[10, 10.625, 12.5, 15.625, 20], [5.625, 6.25, 8.125, 11.25, 15.625], [2.5, 3.125, 5., 8.125, 12.5], [0.625, 1.25, 3.125, 6.25, 10.625], [0, 0.625, 2.5, 5.625, 10]], contours_coloring='lines', line_width=2, ) ) fig.show()
importplotly.graph_objectsasgo# Valid color strings are CSS colors, rgb or hex stringscolorscale= [[0, 'gold'], [0.5, 'mediumturquoise'], [1, 'lightsalmon']] fig=go.Figure(data=go.Contour( z=[[10, 10.625, 12.5, 15.625, 20], [5.625, 6.25, 8.125, 11.25, 15.625], [2.5, 3.125, 5., 8.125, 12.5], [0.625, 1.25, 3.125, 6.25, 10.625], [0, 0.625, 2.5, 5.625, 10]], colorscale=colorscale) ) fig.show()
importplotly.graph_objectsasgofig=go.Figure(data=go.Contour( z=[[10, 10.625, 12.5, 15.625, 20], [5.625, 6.25, 8.125, 11.25, 15.625], [2.5, 3.125, 5., 8.125, 12.5], [0.625, 1.25, 3.125, 6.25, 10.625], [0, 0.625, 2.5, 5.625, 10]], colorbar=dict( title=dict( text='Color bar title', # title hereside='right', font=dict( size=14, family='Arial, sans-serif') ) ), )) fig.show()
In the example below, both the thickness (given here in pixels) and the length (given here as a fraction of the plot height) are set.
importplotly.graph_objectsasgofig=go.Figure(data=go.Contour( z=[[10, 10.625, 12.5, 15.625, 20], [5.625, 6.25, 8.125, 11.25, 15.625], [2.5, 3.125, 5., 8.125, 12.5], [0.625, 1.25, 3.125, 6.25, 10.625], [0, 0.625, 2.5, 5.625, 10]], colorbar=dict( thickness=25, thicknessmode='pixels', len=0.6, lenmode='fraction', outlinewidth=0 ) )) fig.show()
importplotly.graph_objectsasgofig=go.Figure(data=go.Contour( z=[[10, 10.625, 12.5, 15.625, 20], [5.625, 6.25, 8.125, 11.25, 15.625], [2.5, 3.125, 5., 8.125, 12.5], [0.625, 1.25, 3.125, 6.25, 10.625], [0, 0.625, 2.5, 5.625, 10]], colorbar=dict(nticks=10, ticks='outside', ticklen=5, tickwidth=1, showticklabels=True, tickangle=0, tickfont_size=12) )) fig.show()
See https://plotly.com/python/reference/contour/ for more information and chart attribute options!