Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/315.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 熊猫图,带twiny top xticks锚定调整_Python_Matplotlib - Fatal编程技术网

Python 熊猫图,带twiny top xticks锚定调整

Python 熊猫图,带twiny top xticks锚定调整,python,matplotlib,Python,Matplotlib,我有两个长的有孪生情节的画。底部标签看起来不错!两个问题: 标签看起来像是被剪掉了 顶部标签远侧指向刻度,如何调整近侧指向刻度?(使用不同的旋转?) 对标签的水平对齐和savefig调用进行一些调整,以便在保存时标签不会被切断。另外,请确保卸下图autofmt_xdate(旋转=45) 输出: @BigBen谢谢,更新了回答,autofmt_xdate不工作的原因是什么?默认情况下,使用右侧水平对齐-ha='right'。在这里,我想您需要在ax上右对齐,在ax2上左对齐。因此,必须分别设置每

我有两个长的有孪生情节的画。底部标签看起来不错!两个问题:

  • 标签看起来像是被剪掉了
  • 顶部标签远侧指向刻度,如何调整近侧指向刻度?(使用不同的旋转?)


  • 对标签的水平对齐和
    savefig
    调用进行一些调整,以便在保存时标签不会被切断。另外,请确保卸下
    图autofmt_xdate(旋转=45)

    输出:


    @BigBen谢谢,更新了回答,autofmt_xdate不工作的原因是什么?默认情况下,使用右侧水平对齐-
    ha='right'
    。在这里,我想您需要在
    ax
    上右对齐,在
    ax2
    上左对齐。因此,必须分别设置每条路线。
    #!/usr/bin/env python3
    import matplotlib.pyplot as plt
    import pandas as pd
    
    fig = plt.figure()
    ax = fig.add_subplot(111)
    df1 = pd.DataFrame()
    idx = 0
    for i in range(1,50):
        df1.loc[idx,'name'] = 'AAAAAAAAAA' + str(i)
        df1.loc[idx,'value'] = 40*i
        idx += 1
        
    df2 = pd.DataFrame()
    idx = 0
    for i in range(1,50):
        df2.loc[idx,'name'] = 'BBBBBBBBBB' + str(i)
        df2.loc[idx,'value'] = i*i
        idx += 1
    ax2 = ax.twiny()
    df1.plot(x='name',y='value',ax=ax)
    df2.plot(x='name',y='value',ax=ax2)
    
    fig.autofmt_xdate(rotation=45)
    #plt.savefig(pngname)
    plt.show()
    
    ax.set_xticklabels(ax.get_xticklabels(), rotation=45, ha='right')
    ax2.set_xticklabels(ax2.get_xticklabels(), rotation=45, ha='left')
    
    plt.savefig(pngname, bbox_inches='tight')