Plotly 有没有办法访问其范围内任何值的颜色图颜色?
我知道我可以从
plotly.colors.PLOTLY_SCALES["Viridis"]
Run Code Online (Sandbox Code Playgroud)
但我无法找到如何访问中间/插值。
此问题中显示了 Matplotlib 中的等效项。还有另一个问题解决了colorlover图书馆的类似问题,但都没有提供很好的解决方案。
是否可以定义其中定义了多个语句的函数?
我想通过定义函数来自动化创建堆积图所涉及的一些计算。特别是,我希望有类似的东西
mp_setup(bottom_margin, top_margin) = \
set tmargin 0; \
set bmargin 0; \
mp_available_height = 1.0 - top_margin - bottom_margin; \
mp_current_height = bottom_margin;
mp_plot(plot_height) = \
mp_plot_size = plot_height * mp_available_height; \
set origin 0,mp_current_height; \
set size 1,mp_plot_size; \
mp_current_height = mp_current_height + mp_plot_size;
Run Code Online (Sandbox Code Playgroud)
预期用途是:
...
set multiplot
mp_setup(0.05, 0.05)
mp_plot(1.0/3.0)
plot ...
mp_plot(2.0/3.0)
plot ...
Run Code Online (Sandbox Code Playgroud)
这应该会自动导致图很好地堆叠,而无需我计算每个图的原点和大小。
上面定义函数的方法不起作用,因为函数定义的解析似乎在第一次出现 ; 时结束;。但这些分号是必要的,以便分隔每个语句(否则,我们的set tmargin 0 set bmargin 0...语句是无效的)。
Gnuplot 似乎也不支持任何分组语句的方式(如{...}C/C++ 中的);或者至少,我从来没有遇到过。 …
我遇到的情况是,我有一个容器div元素,并且该容器内有一个内部元素(在本例中为图片)。我希望发生以下情况:
我遇到的主要困难是内部元素的高度是可变的。理想情况下,我希望有一个仅 CSS 的解决方案(当然,如果使用 JavaScript 会更容易)。
在内部元素高度已知且固定的情况下,我已设法通过以下方式获得所需的结果(CodePen 链接):
.container {
margin-top: 30px;
margin-bottom: 30px;
background-color: red;
overflow: clip;
height: 100vh;
position: relative;
container-type: size;
}
.inner {
background-image: linear-gradient(green, yellow);
height: 400px;
width: 200px;
}
.option1 {
position: absolute;
@container (max-height: 400px) {
top: 0;
}
@container (min-height: 400px) {
bottom: 0;
}
}Run Code Online (Sandbox Code Playgroud)
<div class="container">
<div class="inner">
</div>
</div>Run Code Online (Sandbox Code Playgroud)
我不知道这是否可以为任何解决方案提供有用的起点。通过访问查询中当前元素的高度可以很容易地解决这个问题@container。