import numpy as np import matplotlib.pyplot as plt # Sample Data data = np.random.randn(30, 30) # Create a heatmap with a sequential colormap plt.imshow(data, cmap='Blues') plt.colorbar() # Adds a color scale legend plt.title('Sequential Colormap Example') plt.show()
import numpy as np import matplotlib.pyplot as plt # Sample Data data = np.random.randn(30, 30) # Heatmap with a diverging colormap plt.imshow(data, cmap='coolwarm') plt.colorbar() plt.title('Diverging Colormap Example') plt.show()
import numpy as np import matplotlib.pyplot as plt # Scatter plot with a qualitative colormap x = np.random.randn(100) y = np.random.randn(100) colors = np.random.randint(0, 5, 100) # Assigning random categories plt.scatter(x, y, c=colors, cmap='Set1') plt.colorbar() plt.title('Qualitative Colormap Example') plt.show()
import numpy as np import matplotlib.pyplot as plt # Sample Data data = np.random.randn(30, 30) # Heatmap with a cyclic colormap plt.imshow(data, cmap='twilight') plt.colorbar() plt.title('Cyclic Colormap Example') plt.show()
import numpy as np import matplotlib.pyplot as plt # Sample Data data = np.random.randn(30, 30) plt.imshow(data, cmap='Blues_r') plt.colorbar() plt.title('Reversed Colormap') plt.show()
import numpy as np import matplotlib.pyplot as plt from matplotlib.colors import ListedColormap # Define custom colors colors = ['#FF0000', '#00FF00', '#0000FF'] custom_cmap = ListedColormap(colors) # Sample Data data = np.random.randn(30, 30) # Apply the custom colormap plt.imshow(data, cmap=custom_cmap) plt.colorbar() plt.title('Custom Colormap') plt.show()
import numpy as np import matplotlib.pyplot as plt import matplotlib.colors as mcolors # Create a new colormap that uses only the first half of the 'Blues' colormap cmap = plt.get_cmap('Blues', 256) new_cmap = mcolors.ListedColormap(cmap(np.linspace(0, 0.5, 256))) # Sample Data data = np.random.randn(30, 30) plt.imshow(data, cmap=new_cmap) plt.colorbar() plt.title('Subset of a Colormap') plt.show()