Defining Colorscale
In plotly, colorscale or color chart is a flat physical object which have different types of colors. It can be set in this graph using the colorscale parameter.
Example 1:
Python3
import plotly.figure_factory as ff import numpy as np feature_x = np.arange( 0 , 10 , 2 ) feature_y = np.arange( 0 , 10 , 3 ) # Creating 2-D grid of features [X, Y] = np.meshgrid(feature_x, feature_y) Z = np.cos(X / 2 ) + np.sin(Y / 4 ) fig = ff.create_annotated_heatmap(Z, colorscale = 'rainbow' ) fig.show() |
Output:
Example 2: Adding Custom Colorscale
Python3
import plotly.figure_factory as ff import numpy as np feature_x = np.arange( 0 , 10 , 2 ) feature_y = np.arange( 0 , 10 , 3 ) # Creating 2-D grid of features [X, Y] = np.meshgrid(feature_x, feature_y) Z = np.cos(X / 2 ) + np.sin(Y / 4 ) custom = [[ 0 , 'green' ], [ 0.5 , 'red' ]] fig = ff.create_annotated_heatmap(Z, colorscale = custom) fig.show() |
Output:
Annotated Heatmaps using Plotly in Python
A Plotly is a Python library that is used to design graphs, especially interactive graphs. It can plot various graphs and charts like histogram, barplot, boxplot, spreadplot, and many more. It is mainly used in data analysis as well as financial analysis. plotly is an interactive visualization library.
Contact Us