【问题标题】:Getting the numpy array describing an arbitrary matplolib/seaborn plot获取描述任意 matplotlib/seaborn 图的 numpy 数组
【发布时间】:2020-02-22 04:23:43
【问题描述】:

是否有可能获得描述任意matplolib/seaborn 绘图的numpy 数组而不 将其显式保存为图像文件并读取它?

例如,假设我有一个数组的sns.kdeplot() 附加图像。现在,我可以在没有第一个saving it to a file 并阅读它的情况下获得这个情节的numpy 数组吗?比如:

img = sns.kdeplot(arr)
img_arr = img.some_function() # Returns a numpy array describing the plot

【问题讨论】:

    标签: python numpy matplotlib seaborn


    【解决方案1】:

    fig.canvas.tostring_rgb() 会有所帮助:

    fig, ax = plt.subplots()
    sns.kdeplot(arr, ax=ax)
    
    img_arr = np.fromstring(fig.canvas.tostring_rgb(), 
                            dtype=np.uint8,
                            sep='')
    

    【讨论】:

      猜你喜欢
      • 2019-10-15
      • 1970-01-01
      • 2016-11-29
      • 1970-01-01
      • 1970-01-01
      • 2022-07-09
      • 1970-01-01
      • 2020-07-02
      • 1970-01-01
      相关资源
      最近更新 更多