我有一张由matplotlib绘制的流线图。我想把与matplotlib(Inferno)相同的颜色。我试图在matplotlib.pyplot.streamplot
中查找与color
相同的函数。有什么方法可以根据数据的值来表示颜色吗?
这就是我对matplotlib.pyplot.streamplot
所做的
enter image description here
我尝试了bokeh.palettes
并且有一个inferno()函数,它根据0~256之间的数字显示inferno颜色。Inferno
它看起来很有效,但颜色的表示方式与matplotlib显示的不同。这是我和博克的结果。enter image description here
Bokeh似乎随机显示颜色,而不是基于值(这意味着值越高,值越亮)。在
from bokeh.layouts import gridplot
from bokeh.models import BasicTickFormatter, ColorBar, BasicTicker, LinearColorMapper
import numpy as np
from bokeh.palettes import Inferno256, inferno
import bokeh.plotting as blt
from streamline import streamlines #a package that I made
for comp in range(0,3):
fig = []
fig.append(blt.figure())
x = np.linspace(-6.02138592, 6.02138592, nElem[0]) #Elem[0] = 24
y = np.linspace(-5.8125, 5.8125, nElem[1]) #Elem[1] = 32
xs, ys = streamlines(x, y, data[..., 6].transpose(), data[...,
7].transpose(), density=1)
''' a fuction to make x velocity and y velocity. here xs and xy are
232 However it varies based on the range of x and y. It means it
could go over 256.'''
magnitude = np.sqrt(values[..., 2*comp]**2
+ values[..., 2*comp+1]**2)
#it will make the lines have color depending on this value
fig[comp].multi_line(xs, ys, color=inferno(len(xs)), line_width=2,
line_alpha=0.8) # I need to change len(xs) because sometimes it
exceeds 256
mapper = LinearColorMapper(palette='Inferno256',
low=np.amin(magnitude.transpose()),
high=np.amax(magnitude.transpose()))
color_bar = ColorBar(color_mapper=mapper,
width=7,
location=(0,0),
formatter=BasicTickFormatter(precision=1),
ticker=BasicTicker(desired_num_ticks=4),
label_standoff=10,
border_line_color=None,
padding=2,
bar_line_color='black')
fig[comp].add_layout(color_bar, 'right')
gp = gridplot(children=fig, toolbar_location='right',
ncols=2, merge_tools=True)
show(gp)
首先创建matplotlib流图:
然后得到线条和颜色数据:
^{pr2}$使用数据创建}设置行的颜色:
multiline
,使用linear_map
和{相关问题 更多 >
编程相关推荐