【问题标题】:Gradient facecolor matplotlib bar plot渐变 facecolor matplotlib 条形图
【发布时间】:2011-07-14 20:35:16
【问题描述】:

如何在我的条形图中添加渐变facecolor?我想知道如何使用简单的单色渐变到复杂的多色渐变。下面是一些示例代码:

import numpy as np
import matplotlib.pyplot as plt

plt.figure(figsize=(1,5))
plt.axis([0,1,-50,200])
plt.xticks([])
plt.yticks([-40,180])
plt.bar(left=0, width=1, bottom=-40, height=220, color='r')
plt.subplots_adjust(left=0.4, right=0.8)
plt.savefig("test.png")

【问题讨论】:

    标签: python colors matplotlib gradient


    【解决方案1】:
    import numpy as np
    import matplotlib as mpl
    import matplotlib.pyplot as plt
    
    # http://matplotlib.sourceforge.net/examples/api/colorbar_only.html
    
    fig=plt.figure(figsize=(1,5))
    ax=fig.add_subplot(111)
    ax.axis([0,1,-50,200])
    cmap = mpl.cm.jet
    norm = mpl.colors.Normalize(vmin=-40, vmax=180)
    cb1 = mpl.colorbar.ColorbarBase(ax, cmap=cmap,
                                    orientation='vertical',                                
                                    norm=norm,
                                    ticks=[-40,180]
                                    )
    
    plt.subplots_adjust(left=0.4, right=0.8)
    plt.show()
    

    【讨论】:

    • 这好像不是脸色?就像set_facecolor in module matplotlib.axes._base 一样,我期待(通过谷歌搜索)一些设置 mpl facecolor 的示例。我不确定 OP 是否想要这个给定的代码(鉴于他们接受了这个答案,也许他们追求的东西与我不同)
    猜你喜欢
    • 2011-06-15
    • 2021-10-14
    • 2020-07-16
    • 2020-05-29
    • 2015-05-20
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多