我正在使用 Chart.js 制作具有线性渐变的图表:
\n\n<script src="js/Chart.min.js"></script>\n<script type="text/javascript">\nvar ctx = document.getElementById(\'myChart\').getContext(\'2d\');\n\nvar grd = ctx.createLinearGradient(0, 0, canvas.width, 0);\ngrd.addColorStop(0.2, \'red\');\ngrd.addColorStop(0.4, \'orange\');\ngrd.addColorStop(0.78, \'limegreen\');\ngrd.addColorStop(0.9, \'black\');\n\nvar chart = new Chart(ctx, {\n // The type of chart we want to create\n type: \'horizontalBar\',\n\n // The data for our dataset\n data: {\n labels: ["Confort"],\n datasets: [\n {\n label: ["Confort actuel"],\n borderWidth: 0,\n borderColor: \'rgba(0,0,0,1.0)\',\n backgroundColor: \'rgba(0,0,0,0.2)\',\n hoverBackgroundColor: \'rgba(0,0,0,0)\',\n data: [64], \n },\n {\n label: ["Confort projet\xc3\xa9"],\n borderWidth: 0,\n borderColor: \'rgba(0,0,0,1.0)\',\n backgroundColor: grd,\n hoverBackgroundColor: grd,\n data: [120],\n },\n {\n …Run Code Online (Sandbox Code Playgroud) 我正在尝试创建水平条形图,并希望根据它们的对数折叠值填充单个条形,白色表示最低值,最暗表示最高值。但是,我无法做到。这是我的工作,有人可以帮我解决吗?
df <- data.frame(LogFold = c(14.20, 14.00, 8.13, 5.3, 3.8, 4.9, 1.3, 13.3, 14.7, 12.2),
Tissue = c("liver", "adrenal", "kidney", "heart", "limb", "adipose", "brown", "hypothalamus", "arcuate", "lung"))
df1<-df%>%
arrange(desc(LogFold))
ggplot(data=df1, aes(x=Tissue, y=LogFold, fill = Tissue)) +
geom_bar(stat="identity")+
scale_colour_gradient2()+
coord_flip()+
ylim(0, 15)+
scale_x_discrete(limits = df1$Tissue)+
theme_classic()
Run Code Online (Sandbox Code Playgroud)
先感谢您!
我的集合视图单元格有一个渐变背景,每个渐变根据单元格是什么标签而不同(例如圣诞节是紫色渐变,生日是绿色渐变)但是当滚动集合视图时,渐变会不断改变单元格. 有没有办法解决这个问题?
这是我用来将渐变设置为背景视图的代码。它在cellForItemAt
cell.mainView.setGradientBackground(colours: self.getColourFromTag(tag: self.lists[indexPath.item].tag))
Run Code Online (Sandbox Code Playgroud)
.setGradientBackground是 UIView 的扩展,它只是为背景设置渐变。此处显示:
func setGradientBackground(colours: [CGColor]) {
let gradientLayer = CAGradientLayer()
gradientLayer.frame = bounds
gradientLayer.colors = colours
gradientLayer.locations = [0.0, 1.0]
gradientLayer.startPoint = CGPoint(x: 1.0, y: 1.0)
gradientLayer.endPoint = CGPoint(x: 0.0, y: 0.0)
layer.insertSublayer(gradientLayer, at: 0)
}
Run Code Online (Sandbox Code Playgroud)
我使用下面的方法来获取渐变中的颜色
func getColourFromTag(tag: String) -> [CGColor] {
if tag == "Christmas" {
return [Colours.gradients.festive.start.cgColor, Colours.gradients.festive.end.cgColor]
}else if tag == "Birthday" {
return [Colours.gradients.lime.start.cgColor, Colours.gradients.lime.end.cgColor]
}else if tag == "Valentines Day" {
return [Colours.gradients.strawberry.start.cgColor, Colours.gradients.strawberry.end.cgColor]
}else …Run Code Online (Sandbox Code Playgroud) 我试图获得 Keras 模型输出相对于模型输入 (x)(不是权重)的导数。似乎最简单的方法是使用来自 keras.backend 的“梯度”,它返回梯度张量(https://keras.io/backend/)。我是 tensorflow 的新手,还不适应。我已经得到了梯度张量,并试图为不同的输入值 (x) 获得它的数值。但似乎梯度值与输入 x 无关(这不是预期的),或者我做错了什么。任何帮助或评论将不胜感激。
import keras
import numpy as np
import matplotlib.pyplot as plt
from keras.layers import Dense, Dropout, Activation
from keras.models import Sequential
import keras.backend as K
import tensorflow as tf
%matplotlib inline
n = 100 # sample size
x = np.linspace(0,1,n) #input
y = 4*(x-0.5)**2 #output
dy = 8*(x-0.5) #derivative of output wrt the input
model = Sequential()
model.add(Dense(32, input_dim=1, activation='relu')) # 1d input
model.add(Dense(32, activation='relu'))
model.add(Dense(1)) # …Run Code Online (Sandbox Code Playgroud) 我有一个用 numpy 绘制径向渐变的代码。到目前为止它看起来像这样:
import numpy as np
import matplotlib.pyplot as plt
arr = np.zeros((256,256,3), dtype=np.uint8)
imgsize = arr.shape[:2]
innerColor = (0, 0, 0)
outerColor = (255, 255, 255)
for y in range(imgsize[1]):
for x in range(imgsize[0]):
#Find the distance to the center
distanceToCenter = np.sqrt((x - imgsize[0]//2) ** 2 + (y - imgsize[1]//2) ** 2)
#Make it on a scale from 0 to 1innerColor
distanceToCenter = distanceToCenter / (np.sqrt(2) * imgsize[0]/2)
#Calculate r, g, and b values
r = outerColor[0] …Run Code Online (Sandbox Code Playgroud) 我有这个 GradientTextView 类,它扩展了 AppCompatTextView
public class GradientTextView extends android.support.v7.widget.AppCompatTextView {
public GradientTextView(Context context) {
super(context);
}
public GradientTextView(Context context, AttributeSet attrs) {
super(context, attrs);
}
public GradientTextView(Context context, AttributeSet attrs, int defStyleAttr) {
super(context, attrs, defStyleAttr);
}
@Override
protected void onLayout(boolean changed, int left, int top, int right, int bottom) {
super.onLayout(changed, left, top, right, bottom);
//Setting the gradient if layout is changed
if (changed) {
getPaint().setShader(new LinearGradient(0, 0, getWidth(), getHeight(),
ContextCompat.getColor(getContext(), R.color.colorStart),//Red Color
ContextCompat.getColor(getContext(), R.color.colorEnd),// Blue Color
Shader.TileMode.CLAMP));
} …Run Code Online (Sandbox Code Playgroud) <svg id="color-gradient" width="400" height="400" version="1.1" xmlns="http://www.w3.org/2000/svg">
<defs>
<linearGradient id="gradient" x1="0" x2="0" y1="0" y2="1">
<stop offset="0%" stop-color="red"/>
<stop offset="50%" stop-color="blue" />
<stop offset="100%" stop-color="yellow"/>
</linearGradient>
</defs>
<circle cx="200" cy="200" r="100" fill="url(#gradient)"/>
</svg>Run Code Online (Sandbox Code Playgroud)
我想在一个有 3 个颜色点的圆圈中创建一个 svg 渐变,以这样的三角形排列。
<svg id="color-gradient" width="400" height="400" version="1.1" xmlns="http://www.w3.org/2000/svg">
<defs>
<linearGradient id="gradient" x1="0" x2="0" y1="0" y2="1">
<stop offset="0%" stop-color="red"/>
<stop offset="50%" stop-color="blue" />
<stop offset="100%" stop-color="yellow"/>
</linearGradient>
</defs>
<circle cx="200" cy="200" r="100" fill="url(#gradient)"/>
</svg>
Run Code Online (Sandbox Code Playgroud)
我尝试创建具有三个停止点的线性渐变,但我不确定如何将停止点放置在我需要的位置(左上右上)。
我正在练习我的编程技能,并且正在尝试使用PyQt. 我是在Login V4之后设计的。现在,当您将鼠标悬停在“登录”按钮上时,我正在尝试通过它实现酷炫的渐变动画。但是CSS动画类似的代码在qt stylesheet. 我使用 Qt Designer 设计了该应用程序。甚至可以在 中创建该动画pyqt吗?如果是,你怎么做?
我的应用程序如下所示:
登录按钮的样式表代码:
QPushButton#login_button {
font: 75 10pt "Microsoft YaHei UI";
font-weight: bold;
color: rgb(255, 255, 255);
background-color: qlineargradient(spread:pad, x1:0, y1:0, x2:1, y2:0, stop:0 rgb(61, 217, 245), stop:1 rgb(240, 53, 218));
border-style: solid;
border-radius:21px;
}
Run Code Online (Sandbox Code Playgroud) 我有两个变量 W1、W2 和输出 z = F(W1,W2) 的损失函数。
现在我绘制这个损失函数的等高线图。现在说,我已经计算了两个点的梯度向量,因此我现在有两个梯度向量。我想在等高线图上绘制这些梯度向量,但我不知道如何处理。任何帮助表示赞赏
enter code here
%matplotlib inline
import matplotlib.pyplot as plt
import numpy as np
feature_x = np.arange(-50, 50, 2)
feature_y = np.arange(-50, 50, 3)
# Creating 2-D grid of features
[X, Y] = np.meshgrid(feature_x, feature_y)
fig, ax = plt.subplots(1, 1)
z = 0.5*np.array((Y-X)*(Y-X) + 0.5*(1-X)*(1-X))
# plots contour lines
ax.contour(X, Y, z, 10, cmap = 'jet')
ax.grid(True)
ax.axis('scaled')
#ax.clabel(cp, inline=1, fontsize=10)
ax.set_title('Contour Plot')
ax.set_xlabel('feature_x')
ax.set_ylabel('feature_y')
plt.show()
Run Code Online (Sandbox Code Playgroud) 我对 HTML 和 CSS 相当陌生。我想创建一个具有渐变背景的进度条,它掩盖了整个元素,但仅在进度条本身上可见。到目前为止,我只得到了如下所示的结果1。我尝试通过操作其他背景属性(例如背景附件)来实现第二张图像中显示的结果,但渐变本身不再适合。我还尝试为栏的父级提供渐变背景,并简单地在剩余空间上方绘制一个白色 div,但该解决方案禁止我向栏本身添加边框半径。非常感谢任何帮助。干杯!
.progress-bar-container {
width: 500px;
height: 50px;
margin: 50px 0px;
background: black;
}
.progress-bar-indicator {
height: 100%;
background-image: linear-gradient(to right, red, green, blue);
border-radius: 25px;
}
#indicator-1 {
width: 80%;
}
#indicator-2 {
width: 50%;
}
#indicator-3 {
width: 20%;
}Run Code Online (Sandbox Code Playgroud)
<div class="progress-bar-container">
<div class="progress-bar-indicator" id="indicator-1"></div>
</div>
<div class="progress-bar-container">
<div class="progress-bar-indicator" id="indicator-2"></div>
</div>
<div class="progress-bar-container">
<div class="progress-bar-indicator" id="indicator-3"></div>
</div>Run Code Online (Sandbox Code Playgroud)