【问题标题】:Barchart sizing of text & barwidth with matplotlib - python使用 matplotlib 调整文本和条宽的条形图大小 - python
【发布时间】:2010-10-17 06:13:46
【问题描述】:

我正在使用 matplotlib-0.91(第一次)创建条形图,但 y 轴标签被切断。如果我将图形的宽度增加得足够多,它们最终会完全显示出来,但是输出的大小不正确。

有什么办法解决吗?

【问题讨论】:

    标签: python matplotlib


    【解决方案1】:

    我想我遇到了类似的问题。

    看看这是否有助于调整标签的字体大小:

    import matplotlib.pyplot as plt
    import matplotlib.font_manager as fm
    
    fontsize2use = 10
    
    fig = plt.figure(figsize=(10,5))
    plt.xticks(fontsize=fontsize2use)  
    plt.yticks(fontsize=fontsize2use)    
    fontprop = fm.FontProperties(size=fontsize2use)
    ax = fig.add_subplot(111)
    ax.set_xlabel('XaxisLabel')
    ax.set_ylabel('YaxisLabel')
    .
    <main plotting code>
    .
    ax.legend(loc=0, prop=fontprop)     
    

    对于条形宽度,如果您使用pyplot.bar,看起来您可以使用宽度属性。

    【讨论】:

      【解决方案2】:

      看看subplots_adjust,或者直接使用axes([left,bottom,width,height])

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2019-09-24
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2014-06-24
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多