- android - 多次调用 OnPrimaryClipChangedListener
- android - 无法更新 RecyclerView 中的 TextView 字段
- android.database.CursorIndexOutOfBoundsException : Index 0 requested, 光标大小为 0
- android - 使用 AppCompat 时,我们是否需要明确指定其 UI 组件(Spinner、EditText)颜色
如何增加绘图“填充”区域的不透明度
或alpha
?我试过:
import pandas as pd
import plotly.offline as py
import plotly.graph_objs as go
import cufflinks as cf
from plotly import tools
plotly.offline.init_notebook_mode()
cf.go_offline()
df = pd.DataFrame(np.random.rand(10, 4), columns=['a', 'b', 'c', 'd'])
df.iplot(kind='area', fill=True, filename='cuflinks/stacked-area', opacity=.1)
但是好像不行。
最佳答案
似乎没有一种简单的内置方法可以实现这一点。但是,解决方法是先获取绘图的图形对象,修改它以更改不透明度,然后再绘制它。
您可以使用 asFigure
属性获取图形对象,如下所示:
figure = df.iplot(asFigure=True, kind='area', fill=True, filename='cuflinks/stacked-area')
本例中的图形对象如下所示:
Figure({
'data': [{'fill': 'tonexty',
'fillcolor': 'rgba(255, 153, 51, 0.3)',
'line': {'color': 'rgba(255, 153, 51, 1.0)', 'dash': 'solid', 'shape': 'linear', 'width': 1.3},
'mode': 'lines',
'name': 'a',
'text': '',
'type': 'scatter',
'uid': '4dcc1a3e-fba3-4a32-bb2a-40925b4fae5b',
'x': array([0, 1, 2, 3, 4, 5, 6, 7, 8, 9], dtype=int64),
'y': array([0.91229144, 0.63049138, 0.22855077, 0.13470399, 0.9114691 , 0.39640368,
0.46534334, 0.20508211, 0.00203548, 0.41343938])},
{'fill': 'tonexty',
'fillcolor': 'rgba(55, 128, 191, 0.3)',
'line': {'color': 'rgba(55, 128, 191, 1.0)', 'dash': 'solid', 'shape': 'linear', 'width': 1.3},
'mode': 'lines',
'name': 'b',
'text': '',
'type': 'scatter',
'uid': '1015b30d-7c09-456c-875c-8a211a6ebdeb',
'x': array([0, 1, 2, 3, 4, 5, 6, 7, 8, 9], dtype=int64),
'y': array([1.81115175, 1.57534372, 0.41288126, 0.38068805, 1.72268856, 0.87778503,
1.32714727, 0.848242 , 0.51605283, 0.58190402])},
{'fill': 'tonexty',
'fillcolor': 'rgba(50, 171, 96, 0.3)',
'line': {'color': 'rgba(50, 171, 96, 1.0)', 'dash': 'solid', 'shape': 'linear', 'width': 1.3},
'mode': 'lines',
'name': 'c',
'text': '',
'type': 'scatter',
'uid': '7d1852ac-b8e7-44e6-ae69-54229d7e2c83',
'x': array([0, 1, 2, 3, 4, 5, 6, 7, 8, 9], dtype=int64),
'y': array([2.79222081, 1.58812634, 1.1439478 , 1.30453731, 2.50881795, 1.67681961,
1.85609861, 1.36657712, 0.89024486, 0.82749039])},
{'fill': 'tonexty',
'fillcolor': 'rgba(128, 0, 128, 0.3)',
'line': {'color': 'rgba(128, 0, 128, 1.0)', 'dash': 'solid', 'shape': 'linear', 'width': 1.3},
'mode': 'lines',
'name': 'd',
'text': '',
'type': 'scatter',
'uid': '89b85012-fc95-487c-b7ba-9cb6c249b768',
'x': array([0, 1, 2, 3, 4, 5, 6, 7, 8, 9], dtype=int64),
'y': array([3.54740551, 1.79856232, 2.1326556 , 2.10560567, 2.64867039, 2.55519564,
2.73888819, 2.23274393, 1.16987343, 1.42794202])}],
'layout': {'legend': {'bgcolor': '#F5F6F9', 'font': {'color': '#4D5663'}},
'paper_bgcolor': '#F5F6F9',
'plot_bgcolor': '#F5F6F9',
'title': {'font': {'color': '#4D5663'}},
'xaxis': {'gridcolor': '#E1E5ED',
'showgrid': True,
'tickfont': {'color': '#4D5663'},
'title': {'font': {'color': '#4D5663'}, 'text': ''},
'zerolinecolor': '#E1E5ED'},
'yaxis': {'gridcolor': '#E1E5ED',
'showgrid': True,
'tickfont': {'color': '#4D5663'},
'title': {'font': {'color': '#4D5663'}, 'text': ''},
'zerolinecolor': '#E1E5ED'}}
})
您会注意到数据中的每条迹线都有一个 fillcolor
属性:'fillcolor': 'rgba(255, 153, 51, 0.3)'
。最后一个数字是您要修改的 alpha 值。我做了一个 hacky 小函数来更新图形对象中所有迹线的 fillcolor
属性:
def update_opacity(figure,opacity):
for trace in range(len(figure['data'])):
# print(figure['data'][trace]['fillcolor'],'-> ',end='')
rgba_split = figure['data'][trace]['fillcolor'].split(',')
figure['data'][trace]['fillcolor'] = ','.join(rgba_split[:-1] + [' {})'.format(opacity)])
# print(figure['data'][trace]['fillcolor'])
return figure
对于完全不透明,你可以这样做:
figure = update_opacity(figure,1)
然后,简单地绘制结果
py.iplot(figure)
输出:
关于python - 在 plotly 中增加区域图的不透明度,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55935108/
我正在制作一个应用程序,我需要使用 ffmpeg 将两个视频文件叠加在另一个之上。 .我尝试了各种命令,但它所做的只是合并视频。 最佳答案 基本方法是 ffmpeg -i in1 -i in2 -fi
我将 Qt3D 与 offscreen renderer 结合使用并修改框架图以包含背景图像,例如 here . 不幸的是,使用 QPhongAlphaMaterial 为绘制在背景图像上的对象添加透
我正在开发的这个组件有视觉问题。它是带有 2 个 JTextField 和 2 个 JLabel 的 JPanel。我不能做坚实的背景。我尝试了几种不透明/背景颜色组合但没有成功。 我不允许附加图像,
我正在使用 Gnuplot 成功绘制一些时间序列数据。然而,该系列相当密集(大约 5 英寸空间中有 10,000 个样本),当我绘制多个系列时,很难看到绘制在顶部的系列下方。 有什么方法可以使线条具有
我正在尝试设置一个自定义拖动图标以在 NSTableView 中使用。一切似乎都正常,但由于我对 Quartz 缺乏经验,我遇到了问题。 - (NSImage *)dragImageForRowsWi
是否可以制作例如 20% 透明的 TMemo 或其他 vcl 组件?像 TButton 或 TEdit 吗? 在谷歌搜索解决方案时,我发现了这个: From Here ,然后我想,如果我在窗体上绘制图
我目前正在学习如何使用 Scenekit,并且遇到了透明对象的问题。我写了一个着色器来增加正面看脸时的透明度,当我选择白色背景时,一切都按预期工作...... transparency with wh
我对 openGL 中的 alpha 混合有疑问... 我尝试了一些绘制透明对象的方法...通过在绘制透明面之前禁用 GL_DEPTH_TEST 并在绘制透明面后再次重新启用 GL_DEPTH_TES
我正试图让我的背景 webView 像那样透明: webView.setBackgroundColor(0x00000000); 但它不起作用,如果我添加这一行,一切都是透明的(我看不到我的 html
我目前正在创建一个应用程序并且出现了这个问题,我想让 TabLayout 透明。当我使用 RelativeLayout TabLayout 覆盖内容时,当我使用 LinearLayout TabLay
我有一个 UINavigationItem(不是 UINavigationBar),我想使其透明或不透明。这是在我建立从导航 Controller 到我的 UIViewController 子类的关系
是否可以让您的 android Activity 以透明模式在当前正在运行的 Activity 之上运行,以便您可以通过它看到它下面的 Activity ?如果可能,您可以设置不同级别的透明度吗? 最
我正在使用 noUiSlider 范围 slider 。这是 jsfiddle: https://jsfiddle.net/oun5p1xz/ behaviourSlider = document.g
有没有办法改变控制台的不透明度使其半透明? 还有办法将控制台的背景颜色更改为自定义颜色吗? 最佳答案 快速谷歌显示 this site其中包含用于具有透明窗口的控制台应用程序的代码。 本质上,您必须获
主.xml: 这是我的 main.xml,我试图使按钮最透明,但我仍然想看到它们,但我不知道要添加什么以及在哪里添加,请用低不透明度更正我的 xml在按钮
如何将实际内容 Pane 的背景设置为不透明,我添加到其中的面板我已经设置为不透明,但即使我这样做,选项卡 Pane 的主要区域仍显示为蓝色 JTabbedPane tabbedPane = new
是否可以继承颜色但覆盖不透明度值?以下是伪 CSS 中的示例: .color-class { background-color: rgba(255, 0, 0, 0); } .lighten
我正在尝试让我的导航栏变得 100% 透明,以便 UINavigationButtonItems 只可见并且背景(通常为白色)应该显示背景图像。 我试过了 HomeNavigationControll
RGBA 非常有趣,-webkit-gradient、-moz-gradient 和呃... progid:DXImageTransform.Microsoft.gradient 也是如此...是的。
我一直在尝试使用 AppBarLayout,但找不到使它的背景透明的方法。 我的意思是: 这是我的 XML: 如您所见,我使用的是颜色 #8000
我是一名优秀的程序员,十分优秀!