本文整理汇总了Python中matplotlib.collections.LineCollection.set_dashes方法的典型用法代码示例。如果您正苦于以下问题:Python LineCollection.set_dashes方法的具体用法?Python LineCollection.set_dashes怎么用?Python LineCollection.set_dashes使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类matplotlib.collections.LineCollection
的用法示例。
在下文中一共展示了LineCollection.set_dashes方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: plot
# 需要导入模块: from matplotlib.collections import LineCollection [as 别名]
# 或者: from matplotlib.collections.LineCollection import set_dashes [as 别名]
#.........这里部分代码省略.........
# For the plotting, we will use the current colorcycle
color_cycle = ax[0]._get_lines.color_cycle
for i in range(nModels):
# Max alpha for the plots
max_alpha = 0.7
# Cited from http://matplotlib.1069221.n5.nabble.com/Varying-alpha-in-ListedColormap-not-working-td39950.html
x = x_plot
y = model_predictions[i,:]
scaling = model_weights[i,:]
points = np.array([x, y]).T.reshape(-1, 1, 2)
segments = np.concatenate([points[:-1],points[1:]], axis=1)
# Values to scale by
smin = 0
smax = 1
# Inline function to convert scaling value to alpha value in [0,1]
alpha = lambda s0:(s0-smin)/(smax-smin)
# Create a (rgba) color description for each line segment
cmap = []
# Get the next color in the colorcycle
color = next(color_cycle)
converter = cl.ColorConverter()
# Get the rgb color tuple and convert it to a list
color_rgba = list(converter.to_rgb(color))
# Add placeholder alpha to get color_rgba
color_rgba.append(0.0)
for a in segments:
# The x-value for the segment
x0 = a.mean(0)[0]
# With scaling value of
s0 = np.interp(x0, x, scaling)
# And alpha value of
a0 = alpha(s0)
# Pop the previous alpha and add the current alpha
color_rgba[3] = a0*max_alpha
# Add the rgba entry to the colormap. Make sure to copy the list
# Using list slicing.
cmap.append(color_rgba[:])
# Create the line collection objecft
lc = LineCollection(segments)
lc.set_color(cmap)
# Set line properties.
# Dashed line
lc.set_dashes('--')
# line width 3.0
lc.set_linewidth(3.0)
ax[0].add_collection(lc)
"""
# Normal plot
#p0_line = ax[0].plot(x_plot, model_predictions[i,:])
# Set line properties for miniplot
#plt.setp(p0_line, linewidth=3.0, alpha=model_weights[i,:], linestyle='--',
# dash_capstyle='round')
"""
# Now plot scatter of observations
for i in range(nModels):
f = bma.quadratic_models[i][0]
ax[0].scatter(X[0,i],f,s=100.0, c="black", alpha=0.5)
# Plot bma predictions
pred_line = ax[0].plot(x_plot,Z)
# Line properties
plt.setp(pred_line, color="black", alpha=0.3, linewidth=3.0)
# Set the plot range
ax[0].set_xlim(x_min, x_max)
ax[0].set_ylim(y_min, y_max)
plt.savefig("figures/"+str(k_fig)+"_bma_model_breakdown.png")
fig3, ax = plt.subplots(2, sharex=True)
model_weights, errors, N_eff = bma.estimate_model_weights(x_grid, return_errors=True)
ax[0].plot(x_plot, N_eff)
### Plot of errors
for i in range(nModels):
p1_line = ax[1].plot(x_plot, errors[i,:])
plt.setp(p1_line, linewidth=3.0, alpha=1.0, linestyle='-',
dash_capstyle='round')
# Set log scale
ax[1].set_yscale('log')
plt.savefig("figures/"+str(k_fig)+"_bma_error_breakdown.png")
示例2: plot
# 需要导入模块: from matplotlib.collections import LineCollection [as 别名]
# 或者: from matplotlib.collections.LineCollection import set_dashes [as 别名]
#.........这里部分代码省略.........
# Create a (rgba) color description for each line segment
cmap = []
# Get the next color in the colorcycle
color = next(color_cycle)
converter = cl.ColorConverter()
# Get the rgb color tuple and convert it to a list
color_rgba = list(converter.to_rgb(color))
# Add placeholder alpha to get color_rgba
color_rgba.append(0.0)
for a in segments:
# The x-value for the segment
x0 = a.mean(0)[0]
# With scaling value of
s0 = np.interp(x0, x, scaling)
# And alpha value of
a0 = alpha(s0)
# Pop the previous alpha and add the current alpha
color_rgba[3] = a0*max_alpha
# Add the rgba entry to the colormap. Make sure to copy the list
# Using list slicing.
cmap.append(color_rgba[:])
# Create the line collection objecft
lc = LineCollection(segments)
lc.set_color(cmap)
# Set line properties.
# Dashed line
lc.set_dashes('-')
# line width 3.0
lc.set_linewidth(3.0)
ax[0].add_collection(lc)
"""
# Normal plot
#p0_line = ax[0].plot(x_plot, model_predictions[i,:])
# Set line properties for miniplot
#plt.setp(p0_line, linewidth=3.0, alpha=model_weights[i,:], linestyle='--',
# dash_capstyle='round')
"""
# Now plot scatter of observations
for i in range(nModels):
f = bma.quadratic_models[i].get_y()
ax[0].scatter(X[0,i],f,s=100.0, c="black", alpha=0.5)
# Plot bma predictions
pred_line = ax[0].plot(x_plot,Z)
# Line properties
plt.setp(pred_line, color="black", alpha=0.3, linewidth=3.0)
# Set the plot range
ax[0].set_xlim(x_min, x_max)
ax[0].set_ylim(y_min, y_max)
# set x axis
ax[4].set_xlabel("x",fontsize=16)
plt.savefig("figures/"+str(k_fig)+"_bma_model_breakdown.png", dpi=dpi)