我很努力地想知道如何为数据集中第3列的bokeh.scatter图生成调色板。 这是一个例子:
from bokeh.plotting import figure, output_file, show import pandas as pd data_headers = ['eastings', 'northings', 'obs'] data_points = pd.read_csv('~/Documents/ds/data.csv', header=None, names=data_headers) my_color_map = [(20, green_val, blue_val) for blue_val, green_val in zip(data_points.obs, 255-data_points.obs)] output_file("scatter.html") p=figure(x_range=(0, 5), y_range=(0, 10)) p.scatter(x=data_points.eastings, y=data_points.northings, size=5, fill_color=my_color_map) show(p)数据集是:
1,3,123 1,4,97 1,5,83 1,6,192 2,3,126 2,3.5,97 2,4.6,102 2,5.8,45而色彩图是一个合理的价差:
>>> my_color_map [(20, 132, 123), (20, 158, 97), (20, 172, 83), (20, 63, 192), (20, 129, 126), (20, 158, 97), (20, 153, 102), (20, 210, 45)]代码工作得很好,除了它没有填充圆圈。 我可以用fill_color(100,100,100)硬连线,以满足自己我可以批量更改颜色,但我想让颜色成为第3列的功能。
我正在尝试学习如何手动执行此操作(即,只填充RGB元组中的绿色和蓝色通道),但我认为我的最终目标是使用调制器调色板(例如,绘制x,y点的颜色) )从booked.palettes相应地着色点。
我也可以在matplotlib中工作,但这里的目的是看看散景是如何工作的! 谢谢你的帮助 :-)
I'm struggling to get my head around how to generate a colour palette for a bokeh.scatter plot from the 3rd column in a dataset. Here's an example:
from bokeh.plotting import figure, output_file, show import pandas as pd data_headers = ['eastings', 'northings', 'obs'] data_points = pd.read_csv('~/Documents/ds/data.csv', header=None, names=data_headers) my_color_map = [(20, green_val, blue_val) for blue_val, green_val in zip(data_points.obs, 255-data_points.obs)] output_file("scatter.html") p=figure(x_range=(0, 5), y_range=(0, 10)) p.scatter(x=data_points.eastings, y=data_points.northings, size=5, fill_color=my_color_map) show(p)The data set is:
1,3,123 1,4,97 1,5,83 1,6,192 2,3,126 2,3.5,97 2,4.6,102 2,5.8,45And the colour map is a reasonable spread thus:
>>> my_color_map [(20, 132, 123), (20, 158, 97), (20, 172, 83), (20, 63, 192), (20, 129, 126), (20, 158, 97), (20, 153, 102), (20, 210, 45)]The code works fine apart from it doesn't fill the circles. I can hardwire it with fill_color(100,100,100) to satisfy myself that I can change the colours in bulk but I want to make the colour a function of the 3rd column.
I'm trying to learn how to do this manually (i.e. just populate the green and blue channels in the RGB tuple) but I think my ultimate aim would be to plot the colour of a point at x,y using a brewer palette (etc) from booked.palettes to colour the point accordingly.
I can also get it working in matplotlib but the aim here is to see how bokeh works! Thanks for any help :-)
最满意答案
传递颜色元组列表目前不起作用 。 相反,您可以将颜色定义转换为字符串,并将字符串列表传递给fill_color
from bokeh.plotting import figure, show, output_notebook import pandas as pd output_notebook() TESTDATA=StringIO("""1,3,123 1,4,97 1,5,83 1,6,192 2,3,126 2,3.5,97 2,4.6,102 2,5.8,45 """) data_headers = ['eastings', 'northings', 'obs'] data_points = pd.read_csv(TESTDATA, header=None, names=data_headers) my_color_map = ["rgb({!s},{!s},{!s})".format(20, green_val, blue_val) for blue_val, green_val in zip(data_points.obs, 255-data_points.obs)] p=figure(x_range=(0, 5), y_range=(0, 10)) p.scatter(x=data_points.eastings, y=data_points.northings, size=25, fill_color=my_color_map) show(p)Passing a list of color tuples doesn't work at the moment. Instead, you can turn your color definitions into strings and pass the list of strings to fill_color
from bokeh.plotting import figure, show, output_notebook import pandas as pd output_notebook() TESTDATA=StringIO("""1,3,123 1,4,97 1,5,83 1,6,192 2,3,126 2,3.5,97 2,4.6,102 2,5.8,45 """) data_headers = ['eastings', 'northings', 'obs'] data_points = pd.read_csv(TESTDATA, header=None, names=data_headers) my_color_map = ["rgb({!s},{!s},{!s})".format(20, green_val, blue_val) for blue_val, green_val in zip(data_points.obs, 255-data_points.obs)] p=figure(x_range=(0, 5), y_range=(0, 10)) p.scatter(x=data_points.eastings, y=data_points.northings, size=25, fill_color=my_color_map) show(p)调色板创建与蟒蛇散景(Colour palette creation with python bokeh)我很努力地想知道如何为数据集中第3列的bokeh.scatter图生成调色板。 这是一个例子:
from bokeh.plotting import figure, output_file, show import pandas as pd data_headers = ['eastings', 'northings', 'obs'] data_points = pd.read_csv('~/Documents/ds/data.csv', header=None, names=data_headers) my_color_map = [(20, green_val, blue_val) for blue_val, green_val in zip(data_points.obs, 255-data_points.obs)] output_file("scatter.html") p=figure(x_range=(0, 5), y_range=(0, 10)) p.scatter(x=data_points.eastings, y=data_points.northings, size=5, fill_color=my_color_map) show(p)数据集是:
1,3,123 1,4,97 1,5,83 1,6,192 2,3,126 2,3.5,97 2,4.6,102 2,5.8,45而色彩图是一个合理的价差:
>>> my_color_map [(20, 132, 123), (20, 158, 97), (20, 172, 83), (20, 63, 192), (20, 129, 126), (20, 158, 97), (20, 153, 102), (20, 210, 45)]代码工作得很好,除了它没有填充圆圈。 我可以用fill_color(100,100,100)硬连线,以满足自己我可以批量更改颜色,但我想让颜色成为第3列的功能。
我正在尝试学习如何手动执行此操作(即,只填充RGB元组中的绿色和蓝色通道),但我认为我的最终目标是使用调制器调色板(例如,绘制x,y点的颜色) )从booked.palettes相应地着色点。
我也可以在matplotlib中工作,但这里的目的是看看散景是如何工作的! 谢谢你的帮助 :-)
I'm struggling to get my head around how to generate a colour palette for a bokeh.scatter plot from the 3rd column in a dataset. Here's an example:
from bokeh.plotting import figure, output_file, show import pandas as pd data_headers = ['eastings', 'northings', 'obs'] data_points = pd.read_csv('~/Documents/ds/data.csv', header=None, names=data_headers) my_color_map = [(20, green_val, blue_val) for blue_val, green_val in zip(data_points.obs, 255-data_points.obs)] output_file("scatter.html") p=figure(x_range=(0, 5), y_range=(0, 10)) p.scatter(x=data_points.eastings, y=data_points.northings, size=5, fill_color=my_color_map) show(p)The data set is:
1,3,123 1,4,97 1,5,83 1,6,192 2,3,126 2,3.5,97 2,4.6,102 2,5.8,45And the colour map is a reasonable spread thus:
>>> my_color_map [(20, 132, 123), (20, 158, 97), (20, 172, 83), (20, 63, 192), (20, 129, 126), (20, 158, 97), (20, 153, 102), (20, 210, 45)]The code works fine apart from it doesn't fill the circles. I can hardwire it with fill_color(100,100,100) to satisfy myself that I can change the colours in bulk but I want to make the colour a function of the 3rd column.
I'm trying to learn how to do this manually (i.e. just populate the green and blue channels in the RGB tuple) but I think my ultimate aim would be to plot the colour of a point at x,y using a brewer palette (etc) from booked.palettes to colour the point accordingly.
I can also get it working in matplotlib but the aim here is to see how bokeh works! Thanks for any help :-)
最满意答案
传递颜色元组列表目前不起作用 。 相反,您可以将颜色定义转换为字符串,并将字符串列表传递给fill_color
from bokeh.plotting import figure, show, output_notebook import pandas as pd output_notebook() TESTDATA=StringIO("""1,3,123 1,4,97 1,5,83 1,6,192 2,3,126 2,3.5,97 2,4.6,102 2,5.8,45 """) data_headers = ['eastings', 'northings', 'obs'] data_points = pd.read_csv(TESTDATA, header=None, names=data_headers) my_color_map = ["rgb({!s},{!s},{!s})".format(20, green_val, blue_val) for blue_val, green_val in zip(data_points.obs, 255-data_points.obs)] p=figure(x_range=(0, 5), y_range=(0, 10)) p.scatter(x=data_points.eastings, y=data_points.northings, size=25, fill_color=my_color_map) show(p)Passing a list of color tuples doesn't work at the moment. Instead, you can turn your color definitions into strings and pass the list of strings to fill_color
from bokeh.plotting import figure, show, output_notebook import pandas as pd output_notebook() TESTDATA=StringIO("""1,3,123 1,4,97 1,5,83 1,6,192 2,3,126 2,3.5,97 2,4.6,102 2,5.8,45 """) data_headers = ['eastings', 'northings', 'obs'] data_points = pd.read_csv(TESTDATA, header=None, names=data_headers) my_color_map = ["rgb({!s},{!s},{!s})".format(20, green_val, blue_val) for blue_val, green_val in zip(data_points.obs, 255-data_points.obs)] p=figure(x_range=(0, 5), y_range=(0, 10)) p.scatter(x=data_points.eastings, y=data_points.northings, size=25, fill_color=my_color_map) show(p)
发布评论