Plotting with a transparent marker but non-transparent edge

前端 未结 2 1367
执念已碎
执念已碎 2020-12-24 05:48

I\'m trying to make a plot in matplotlib with transparent markers which have a fixed color edge . However, I can\'t seem to achieve a marker with transparent fill.

相关标签:
2条回答
  • 2020-12-24 06:03

    This is tricky in Matplotlib... you have to use a string "None" instead of the value None, then you can just do:

    plt.plot(x,y2, 'o', ms=14, markerfacecolor="None",
             markeredgecolor='red', markeredgewidth=5)
    
    0 讨论(0)
  • 2020-12-24 06:08

    In general it seems to be a better solution to use transparent colors, instead of the alpha parameter. First of all because it does not affect any other colors and it helps to avoid the black fill bug reported by some in the comments. In this example - using the voxels function to draw 2 voxels on the plot - the 4th number in the tuples stored in colors represents the alpha value of an RGBA color. These normalized RGBA tuple notations can be used as colors throughout matplotlib.

    import matplotlib.pyplot as plt, numpy as np, mpl_toolkits.mplot3d
    fig = plt.figure()
    ax = fig.gca(projection='3d')
    voxels = np.array([[[True],[True]]])
    colors = np.array([[[(0., 0., 0., 0.)],[(1.0, 0., 0., 0.5)]]])
    ax.voxels(voxels, facecolors=colors, edgecolor='k', linewidth=.5)
    plt.show(block=True)
    

    0 讨论(0)
提交回复
热议问题