【问题标题】:How to get matplolib to output SVGs with fill-opacity instead of opacity如何让 matplotlib 输出具有填充不透明度而不是不透明度的 SVG
【发布时间】:2020-03-06 01:29:56
【问题描述】:

在使用 SVG 导出带有碧玉的 pdf 文件时,我遇到了透明度问题:Jasper export pdf with transparent SVG

问题是如何让 matplotlib 导出具有填充不透明度而不是简单不透明度的 SVG。

【问题讨论】:

    标签: python matplotlib svg


    【解决方案1】:

    我在这里找到了与 SVG 相关的 matplotlib 的来源:matplotlib svg backend

    我发现了这个:

                if (rgbFace is not None and len(rgbFace) == 4 and rgbFace[3] != 1.0
                    and not forced_alpha):
                attrib['fill-opacity'] = short_float_fmt(rgbFace[3])
    

    还有这个:

                    if (len(rgbFace) == 4 and rgbFace[3] != 1.0
                        and not forced_alpha):
                    attrib['fill-opacity'] = short_float_fmt(rgbFace[3])
    

    这看起来很有希望,我开始测试如何让该代码执行。 原来你必须关闭透明度(alpha)! 此外,您必须使用 RGBA 而不是 RGB 十六进制颜色。就我而言,我想要图例周围的半透明框,我最初有:

    bbox_args = dict(boxstyle="square", fc="W", alpha=0.5)
    

    为了让它工作,我把它改成了:

    bbox_args = dict(boxstyle="square", fc="#FFFFFF80")
    

    之后,导出的 svg 具有填充不透明度而不是不透明度。 但请注意,不透明度和填充不透明度都可能适用于您的情况。在 Chrome 中,两者都有效,但只有填充不透明度在我从 jasperreports 导出的 pdf 中有效。

    【讨论】:

      猜你喜欢
      • 2016-10-12
      • 1970-01-01
      • 1970-01-01
      • 2013-11-12
      • 2011-07-05
      • 2017-01-11
      • 1970-01-01
      • 1970-01-01
      • 2017-10-04
      相关资源
      最近更新 更多