zoukankan      html  css  js  c++  java
  • matplotlib---6.path effect

    1.matplotlibpatheffects模块

      matplotlibpatheffects模块提供了一些函数来绘制path effect,该模块还定义了很多effect类。可以应用path effectArtist有:PatchLine2DCollection以及Text。每个Artistpath effect可以通过.set_path_effects()方法控制,其参数是一个可迭代对象,迭代的结果是AbstractPathEffect实例;也可以通过Artist构造函数的path_effects=关键字参数控制。

    注意:effect类的关键字参数比如背景色、前景色等与Artist不同。因为这些effect类是更低层次的操作。

    2.所有的effect类都继承自matplotlib.patheffects.AbstractPathEffectAbstractPathEffect的子类要覆盖AbstractPathEffect类的.draw_path(...)方法。

    AbstractPathEffect类的构造函数有个offset关键字参数,表示effect偏移(默认为(0,0))

    3.最简单的effectnormal effect,它是matplotlib.patheffects.Normal类。它简单的绘制Artist,不带任何effect

    如:

      import matplotlib.pyplot as plt
      import matplotlib.patheffects as path_effects
      fig = plt.figure(figsize=(5, 1.5))
      text = fig.text(0.5, 0.5, 'Hello path effects world!
    This is the normal path effect.',
      ha='center', va='center', size=20)
      text.set_path_effects([path_effects.Normal()])
      plt.show()
    

    4.我们可以在基于PathArtist上应用drop-shadow effect(下沉效果)。

    例如可以在filled patch Artist上应用matplotlib.patheffects.SimplePatchShadow,在line patch Artist上应用matplotlib.patheffects.SimpleLineShadow

    可以通过path_effects=[path_effects.with*()]来指定path_effects参数,或者直接通过path_effects=[path_effects.SimpleLineShadow(),path_effects.Normal()]来指定path_effects参数。

    1. 前者会自动地在normal effect后跟随指定的effect
    2. 后者会显式的指定effect
    import matplotlib.pyplot as plt
    import matplotlib.patheffects as path_effects
    text = plt.text(0.5, 0.5, 'Hello path effects world!',
         path_effects=[path_effects.withSimplePatchShadow()])
    plt.plot([0,3,2,5],linewidth=5,color='blue',
            path_effects=[path_effects.SimpleLineShadow(),path_effects.Normal()])
    text.set_path_effects([path_effects.Normal()])
    plt.show()
    

    5.Strok effect可以用于制作出stand-out effect(突出效果)。 

    import matplotlib.pyplot as plt
    import matplotlib.patheffects as path_effects
    fig = plt.figure(figsize=(8,6))
    text = plt.text(0.5,0.5,'Hello path effects world!',color='white',ha='center',va='center',size=30)
    text.set_path_effects([path_effects.Stroke(linewidth=3,foreground='black'),path_effects.Normal()])
    plt.show()

    6.PathPatchEffect是一个通用的path effect类。如果对某个PathPatch设置了PathPatchEffect,则该effect.draw_path(...)方法执行的是由初始PathPatch计算的得到的一个新的PathPatch

    与一般的effect类不同,PathPatchEffect类的关键字参数是与PathPatch一致的,因为除了offset关键字参数外,其他的任何关键字参数都会传递给PathPatch构造函数。如:

    import matplotlib.pyplot as plt
    import matplotlib.patheffects as path_effects
    fig = plt.figure(figsize=(8, 1))
    t = fig.text(0.02, 0.5, 'Hatch shadow', fontsize=75, weight=1000, va='center')
    t.set_path_effects([path_effects.PathPatchEffect(offset=(4, -4), hatch='xxxx',
    facecolor='gray'),
    path_effects.PathPatchEffect(edgecolor='white', linewidth=1.1,
    facecolor='black')])
    plt.show()

  • 相关阅读:
    Android BitmapFactory.Options
    Android TabHost
    Android 黑色样式menu
    Android Tab与TabHost
    Android Theme
    Activity 四种launchMode
    IOS xcode安装
    BaseActivity合集
    自定义BaseActivity
    Fragment 底部菜单栏
  • 原文地址:https://www.cnblogs.com/nxf-rabbit75/p/12109182.html
Copyright © 2011-2022 走看看