python matplotlib_routines.py

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了python matplotlib_routines.py相关的知识,希望对你有一定的参考价值。

def corr_plot(df, ylabel2=None, title=None):
    if isinstance(ylabel2, pd.Series):
        ylabel2 = ylabel2.values
    corrmat = df.corr().round(2)
    cols = df.columns.values
    ncols = len(cols)
    
    plt.figure(figsize = (len(cols)/2 , len(cols)/2))
    if title is not None:
        plt.title(title)
        
    mask = np.zeros_like(corrmat)
    mask[np.triu_indices_from(mask,k=1)] = True
    ax = sns.heatmap(corrmat, mask=mask, cmap='coolwarm', linewidths=0.5, annot=True, cbar=False, vmin=0, vmax=1)
    
    if ylabel2 is not None:
        assert len(ylabel2) == len(cols)
        for kth in range(ncols):
            ax.text(kth + 1.1, ncols - 0.6 - kth, ylabel2[kth], fontsize=11) 
            
# trick from https://stackoverflow.com/questions/4325733/save-a-subplot-in-matplotlib
def full_extent(self, ax, pad=0.2):
  """Get the full extent of an axes """
  # For text objects, we need to draw the figure first, otherwise the extents
  # are undefined.
  ax.figure.canvas.draw()
  items = ax.get_xticklabels() + ax.get_yticklabels()
  items += ax.texts
  items += [ax, ax.title, ax.xaxis.label, ax.yaxis.label]
  bbox = Bbox.union([item.get_window_extent() for item in items])
  return bbox.expanded(1.0 + pad, 1.0 + pad)

以上是关于python matplotlib_routines.py的主要内容,如果未能解决你的问题,请参考以下文章

001--python全栈--基础知识--python安装

Python代写,Python作业代写,代写Python,代做Python

Python开发

Python,python,python

Python 介绍

Python学习之认识python