本文整理汇总了Python中matplotlib.colors.LightSource.shade_rgb方法的典型用法代码示例。如果您正苦于以下问题:Python LightSource.shade_rgb方法的具体用法?Python LightSource.shade_rgb怎么用?Python LightSource.shade_rgb使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类matplotlib.colors.LightSource
的用法示例。
在下文中一共展示了LightSource.shade_rgb方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: LightFilter
# 需要导入模块: from matplotlib.colors import LightSource [as 别名]
# 或者: from matplotlib.colors.LightSource import shade_rgb [as 别名]
class LightFilter(BaseFilter):
"simple gauss filter"
def __init__(self, sigma, fraction=0.5):
self.gauss_filter = GaussianFilter(sigma, alpha=1)
self.light_source = LightSource()
self.fraction = fraction
#hsv_min_val=0.5,hsv_max_val=0.9,
# hsv_min_sat=0.1,hsv_max_sat=0.1)
def get_pad(self, dpi):
return self.gauss_filter.get_pad(dpi)
def process_image(self, padded_src, dpi):
t1 = self.gauss_filter.process_image(padded_src, dpi)
elevation = t1[:,:,3]
rgb = padded_src[:,:,:3]
rgb2 = self.light_source.shade_rgb(rgb, elevation,
fraction=self.fraction)
tgt = np.empty_like(padded_src)
tgt[:,:,:3] = rgb2
tgt[:,:,3] = padded_src[:,:,3]
return tgt
示例2: shade_other_data
# 需要导入模块: from matplotlib.colors import LightSource [as 别名]
# 或者: from matplotlib.colors.LightSource import shade_rgb [as 别名]
def shade_other_data():
"""Demonstrates displaying different variables through shade and color."""
y, x = np.mgrid[-4:2:200j, -4:2:200j]
z1 = np.sin(x**2) # Data to hillshade
z2 = np.cos(x**2 + y**2) # Data to color
norm = Normalize(z2.min(), z2.max())
cmap = plt.cm.RdBu
ls = LightSource(315, 45)
rgb = ls.shade_rgb(cmap(norm(z2)), z1)
fig, ax = plt.subplots()
ax.imshow(rgb)
ax.set_title('Shade by one variable, color by another', size='x-large')
示例3: xrange
# 需要导入模块: from matplotlib.colors import LightSource [as 别名]
# 或者: from matplotlib.colors.LightSource import shade_rgb [as 别名]
for j in xrange(0,i,1):
if(np.linalg.norm(X[i]-X[j])<=1.3*d[i]):
ax1.plot([ X[i][0],X[j][0] ], [ X[i][1],X[j][1] ], [ X[i][2],X[j][2] ],linewidth=3,alpha=0.7,color='black')
X=np.transpose(X)
ax1.scatter(X[0], X[1], X[2], s=600, marker='.',color='b')
ax1.axis('off')
#Make sphere
r = 1.00
pi = np.pi
cos = np.cos
sin = np.sin
phi, theta = np.mgrid[0.0:pi:100j, 0.0:2.0*pi:100j]
x = r*sin(phi)*cos(theta)
y = r*sin(phi)*sin(theta)
z = r*cos(phi)
white = np.ones((z.shape[0], z.shape[1], 3))
red = white * np.array([0.1,.1,.1])
green = white * np.array([0,1,0])
blue = white * np.array([0,0,1])
light = LightSource(60, 45)
illuminated_surface = light.shade_rgb(red, z)
ax1.plot_surface(x, y, z, rstride=1, cstride=1, antialiased=False, color='white', alpha=0.2, linewidth=0)
#Show nearest neighbor distances
#print("average dist: {}".format(np.average(d)))
plt.show()
示例4: show_plot
# 需要导入模块: from matplotlib.colors import LightSource [as 别名]
# 或者: from matplotlib.colors.LightSource import shade_rgb [as 别名]
def show_plot(self, x_points: np.array, y_points: np.array, data: np.ndarray,
map_plot: bool, **kwargs) -> bool:
"""
Displays the plot to the user.
:param x_points: X co-ordinates for the data points.
:param y_points: Y co-ordinates for the data points.
:param data: The data points as a 1D grid, X-fast.
:param map_plot: If set to true, the data is plotted on a map. If false, just generic data.
:return: True, if plot was shown successfully. False if not.
"""
ranges = {
"min_lon": np.amin(x_points),
"max_lon": np.amax(x_points),
"min_lat": np.amin(y_points),
"max_lat": np.amax(y_points)
}
colormap = cm.RdBu
norm = mcolors.Normalize(vmin=self.bounds[0], vmax=self.bounds[len(self.bounds) - 1])
faults = False
save = False
if "basic" in kwargs:
basic = kwargs["basic"]
else:
basic = False
if hasattr(self, "extras"):
if "data" in self.extras:
if "save" in self.extras["data"]:
if str(self.extras["data"]["save"]).lower() == "y":
save = os.path.join(self.extras["data"]["location"], self.extras["data"]["name"] + ".png")
if "plot" in self.extras:
if "save" in self.extras["plot"]:
save = self.extras["plot"]["save"]
if "features" in self.extras["plot"]:
if "colormap" in self.extras["plot"]["features"]:
try:
colormap = getattr(
cm, self.extras["plot"]["features"]["colormap"]
)
except AttributeError:
colormap = getattr(
basemapcm, self.extras["plot"]["features"]["colormap"]
)
if "scale" in self.extras["plot"]["features"]:
if str(self.extras["plot"]["features"]["scale"]).lower().strip() \
== "discrete":
colormap = self._cmapDiscretize(colormap, len(self.bounds) - 1)
norm = mcolors.BoundaryNorm(self.bounds, colormap.N)
if "faults" in self.extras["plot"]["features"]:
if str(self.extras["plot"]["features"]["faults"]).lower().strip() == "yes":
faults = True
if map_plot:
colormap.set_bad("gray", 1)
if not basic:
plt.axes([0.15, 0.2, 0.70, 0.70])
# Check to see if we have pickled this particular basemap instance.
m = basemap.Basemap(projection='cyl',
llcrnrlat=ranges["min_lat"],
urcrnrlat=ranges["max_lat"],
llcrnrlon=ranges["min_lon"],
urcrnrlon=ranges["max_lon"],
resolution='f',
anchor='C')
if not basic:
lat_ticks = np.arange(ranges["min_lat"], ranges["max_lat"],
(ranges["max_lat"] - ranges["min_lat"]) / 2)
lat_ticks = np.append(lat_ticks, [ranges["max_lat"]])
lon_ticks = np.arange(ranges["min_lon"], ranges["max_lon"],
(ranges["max_lon"] - ranges["min_lon"]) / 2)
lon_ticks = np.append(lon_ticks, [ranges["max_lon"]])
lat_ticks = [round(x, 2) for x in lat_ticks]
lon_ticks = [round(x, 2) for x in lon_ticks]
m.drawparallels(lat_ticks, linewidth=1.0, labels=[1, 0, 0, 0])
m.drawmeridians(lon_ticks, linewidth=1.0, labels=[0, 0, 0, 1])
data_cpy = np.ma.masked_invalid(data)
if "topography" in kwargs and kwargs["topography"] is not None:
# create light source object.
ls = LightSource(azdeg=315, altdeg=45)
# convert data to rgb array including shading from light source.
# (must specify color map)
low_indices = kwargs["topography"] < 0
kwargs["topography"][low_indices] = 0
rgb = ls.shade_rgb(colormap(norm(data_cpy)), kwargs["topography"],
blend_mode="overlay", vert_exag=2)
for y in range(len(rgb)):
for x in range(len(rgb[0])):
rgb[y][x][0] *= 0.90
rgb[y][x][1] *= 0.90
rgb[y][x][2] *= 0.90
t = m.imshow(rgb, cmap=colormap, norm=norm)
#.........这里部分代码省略.........