Python 尝试使用matplotlib(平行坐标?)

Python 尝试使用matplotlib(平行坐标?),python,matplotlib,plot,Python,Matplotlib,Plot,我试图可视化一个已排序的表(按列排序)。我的理想结果应该是 关于如何使用matplotlib实现这一目标,有什么建议吗 我已经尝试过给出的建议,但我在附件中寻找一些更喜欢的东西 提前感谢,Matplotlib不直接支持此功能,但复制链接到的绘图相当容易 下面的函数在给定2d数据数组时执行类似的操作。它可以排序,也可以不排序,函数并不真正关心 import matplotlib.pyplot as plt import matplotlib.colors as mcolors import nu

我试图可视化一个已排序的表(按列排序)。我的理想结果应该是

关于如何使用matplotlib实现这一目标,有什么建议吗

我已经尝试过给出的建议,但我在附件中寻找一些更喜欢的东西


提前感谢,

Matplotlib不直接支持此功能,但复制链接到的绘图相当容易

下面的函数在给定2d数据数组时执行类似的操作。它可以排序,也可以不排序,函数并不真正关心

import matplotlib.pyplot as plt
import matplotlib.colors as mcolors
import numpy as np

def sorted_table_plot(data, labels, categories, cmap=None, ax=None):

    # check if an axes was supplied
    if ax is None:
        ax = plt.gca()

    # check if a colormap was supplied
    if cmap is None:
        cmap = plt.cm.jet

    # generate the grid arrays with the coordinates for the annotations
    yy, xx = np.mgrid[:data.shape[0], :data.shape[1]]
    x = xx.flatten()
    y = yy.flatten()
    d = data.flatten()

    # a norm object which we will use with the colorbar
    norm = plt.Normalize(d.min(), d.max())

    # iterate over the data points and draw the labels
    for di, xi, yi in zip(d, x, y):
        color = cmap(norm(di))
        hsv = mcolors.rgb_to_hsv(color[:3])
        fc = 'w' if hsv[2] < 0.7 else 'k'
        ax.annotate(str(di), xy=(xi,yi), xycoords="data",
                va="center", ha="center", color=fc,
                bbox=dict(boxstyle="circle", fc=color))

    # iteratve over all the appearing values and draw the lines
    for i in np.unique(data):
        xi, yi = x[d==i], y[d==i]
        idx = np.argsort(xi)
        plt.plot(xi[idx], yi[idx], color=plt.cm.jet(norm(i)), lw=2)

    # add the axes labels
    ax.set_xticks(xx[0,:])
    ax.set_xticklabels(categories)
    ax.set_yticks(yy[:,0])
    ax.set_yticklabels(labels)

    # adjust the axes ranges
    ax.set_xlim(xx[0,0] - 0.5, xx[-1,-1] + 0.5)
    ax.set_ylim(yy[-1,-1] + 0.5, yy[0,0] - 0.5)
结果:


Matplotlib不直接支持此功能,但复制链接到的绘图相当容易

下面的函数在给定2d数据数组时执行类似的操作。它可以排序,也可以不排序,函数并不真正关心

import matplotlib.pyplot as plt
import matplotlib.colors as mcolors
import numpy as np

def sorted_table_plot(data, labels, categories, cmap=None, ax=None):

    # check if an axes was supplied
    if ax is None:
        ax = plt.gca()

    # check if a colormap was supplied
    if cmap is None:
        cmap = plt.cm.jet

    # generate the grid arrays with the coordinates for the annotations
    yy, xx = np.mgrid[:data.shape[0], :data.shape[1]]
    x = xx.flatten()
    y = yy.flatten()
    d = data.flatten()

    # a norm object which we will use with the colorbar
    norm = plt.Normalize(d.min(), d.max())

    # iterate over the data points and draw the labels
    for di, xi, yi in zip(d, x, y):
        color = cmap(norm(di))
        hsv = mcolors.rgb_to_hsv(color[:3])
        fc = 'w' if hsv[2] < 0.7 else 'k'
        ax.annotate(str(di), xy=(xi,yi), xycoords="data",
                va="center", ha="center", color=fc,
                bbox=dict(boxstyle="circle", fc=color))

    # iteratve over all the appearing values and draw the lines
    for i in np.unique(data):
        xi, yi = x[d==i], y[d==i]
        idx = np.argsort(xi)
        plt.plot(xi[idx], yi[idx], color=plt.cm.jet(norm(i)), lw=2)

    # add the axes labels
    ax.set_xticks(xx[0,:])
    ax.set_xticklabels(categories)
    ax.set_yticks(yy[:,0])
    ax.set_yticklabels(labels)

    # adjust the axes ranges
    ax.set_xlim(xx[0,0] - 0.5, xx[-1,-1] + 0.5)
    ax.set_ylim(yy[-1,-1] + 0.5, yy[0,0] - 0.5)
结果:


我认为matplotlib不支持这种绘图。欢迎使用。我回答了你的问题,尽管它实际上不符合SO:SO的标准,但它不是一种编码服务,因此通常你不会得到答案,除非你展示你自己尝试过的内容(是的,发布代码)以及失败的地方。我认为matplotlib不支持这种绘图。欢迎使用SO。我回答了你的问题,尽管它并不真正符合SO的标准:SO不是一种编码服务,所以通常你不会得到答案,除非你展示你自己尝试过的东西(是的,发布你的代码)以及失败的地方。