colormap

Unsure how to use colormap with Folium marker plot

丶灬走出姿态 提交于 2020-08-27 07:09:25
问题 I have a dataframe with latitude, longitude, and power percentage. I want to do something very simple but not sure how: apply a colormap to color the data points based on their percentage. So 90% is red and 100% is blue. I have created both a successful map and colormap, but not sure how to proceed next. import folium import pandas as pd import folium.plugins import branca import branca.colormap as cm data = [ [33.823400, -118.12194, 99.23], [33.823500, -118.12294, 95.23], [33.823600, -118

Add a vertical label to matplotlib colormap legend

送分小仙女□ 提交于 2020-07-20 11:38:06
问题 This code enables me to plot a colormap of a "3d" array [X,Y,Z] (they are 3 simple np.array of elements). But I can't succeed in adding a vertical written label at the right of the colorbar legend. import numpy as np import matplotlib.pyplot as plt fig = plt.figure("Color MAP 2D+") contour = plt.tricontourf(X, Y, Z, 100, cmap="bwr") plt.xlabel("X") plt.ylabel("Y") plt.title("Color MAP 2D+") #Legend def fmt(x, pos): a, b = '{:.2e}'.format(x).split('e') b = int(b) return r'${} \times 10^{{{}}}$

Making sure 0 gets white in a RdBu colorbar

浪尽此生 提交于 2020-05-23 10:12:32
问题 I create a heatmap with the following snippet: import numpy as np import matplotlib.pyplot as plt d = np.random.normal(.4,2,(10,10)) plt.imshow(d,cmap=plt.cm.RdBu) plt.colorbar() plt.show() The result is plot below: Now, since the middle point of the data is not 0, the cells in which the colormap has value 0 are not white, but rather a little reddish. How do I force the colormap so that max=blue, min=red and 0=white? 回答1: Use a DivergingNorm: import numpy as np import matplotlib.pyplot as plt

Matplotlib scatter plot different colors in legend and plot

ε祈祈猫儿з 提交于 2020-01-30 02:48:29
问题 I have a scatter plot of multiple y-values for the same x-value, in matplotlib (python 2.7). There are different colors for all the plotted y-values. See the plot below. Now, here is the code: import numpy as np import pandas as pd import matplotlib.pyplot as plt import pylab as pl import matplotlib.cm as cm # Generate test x, y and y_error values: df2a = pd.DataFrame(np.random.rand(10,5), columns = list('ABCDE')) df2a.insert(0,'x_var_plot',range(1,df2a.shape[0]+1)) df2a_err = pd.DataFrame(np

pyplot contourf with custom colormap repeats color instead of changing

|▌冷眼眸甩不掉的悲伤 提交于 2020-01-24 12:52:10
问题 I want to plot some data with a logarithmic color code where a decade limit is indicated by a white/black interface. Grey levels are used to show some subdivisions of a decade. My problem is that there are two white neighboring regions in each decade even though the color map has the right number of entries (at least I think). Could someone help please? In the meantime I made some tests and I found that it's the second color of the repeating pattern that is not used (the gray(0.25)), but I

Custom Colormap

安稳与你 提交于 2020-01-23 13:04:13
问题 I want to plot a heatmap with a custom colormap similar to this one, although not exactly. I'd like to have a colormap that goes like this. In the interval [-0.6, 0.6] the color is light grey. Above 0.6, the color red intensifies. Below -0.6 another color, say blue, intensifies. How can I create such a colormap using python and matplotlib? What I have so far: In seaborn there is the command seaborn.diverging_palette(220, 10, as_cmap=True) which produces a colormap going from blue-light grey

Using perceptually uniform colormaps in Mayavi volumetric visualization

懵懂的女人 提交于 2020-01-23 12:47:11
问题 AFAIK Mayavi does not come with any perceptually uniform colormaps. I tried naively to just pass it one of Matplotlib's colormaps but it failed: from mayavi import mlab import multiprocessing import matplotlib.pyplot as plt plasma = plt.get_cmap('plasma') ... mlab.pipeline.volume(..., colormap=plasma) TraitError: Cannot set the undefined 'colormap' attribute of a 'VolumeFactory' object. Edit: I found a guide to convert Matplotlib colormaps to Mayavi colormaps. However, it unfortunately doesn

Matplotlib colormap bug with length-4 arrays

淺唱寂寞╮ 提交于 2020-01-21 12:13:20
问题 I have some arrays that I need to plot in a loop with a certain colormap. However, one of my arrays is length-4, and I run into this problem: import numpy as np import matplotlib as plt ns = range(2,8) cm = plt.cm.get_cmap('spectral') cmap = [cm(1.*i/len(ns)) for i in range(len(ns))] for i,n in enumerate(ns): x = np.linspace(0, 10, num=n) y = np.zeros(n) + i plt.scatter(x, y, c=cmap[i], edgecolor='none', s=50, label=n) plt.legend(loc='lower left') plt.show() For n=4 , it looks like Matplotlib