Kann man mit matplotlib nur einen Tisch zeichnen? Wenn ich die Zeile nicht kommentiere
plt.bar(index, data[row], bar_width, bottom=y_offset, color=colors[row])
von diesem Beispiel code ist der Plot noch sichtbar. Ich möchte eine Tabelle über meinem (PyQt) -Fenster und unter einem Diagramm (mit etwas Abstand dazwischen) haben.
Wenn Sie nur das example ändern und die Tabelle an die oberste Stelle setzen möchten, benötigen Sie loc='top'
in der Tabellendeklaration.
the_table = ax.table(cellText=cell_text,
rowLabels=rows,
rowColours=colors,
colLabels=columns,
loc='top')
Passen Sie dann die Darstellung mit
plt.subplots_adjust(left=0.2, top=0.8)
Eine flexiblere Option besteht darin, die Tabelle mithilfe von Unterplots in die eigene Achse zu setzen.
import numpy as np
import matplotlib.pyplot as plt
fig, axs =plt.subplots(2,1)
clust_data = np.random.random((10,3))
collabel=("col 1", "col 2", "col 3")
axs[0].axis('tight')
axs[0].axis('off')
the_table = axs[0].table(cellText=clust_data,colLabels=collabel,loc='center')
axs[1].plot(clust_data[:,0],clust_data[:,1])
plt.show()
was so aussieht,
Sie können dann die Positionen der Achse als required anpassen.
Dies ist eine weitere Option, um einen Pandas-Datenrahmen direkt in eine Matplotlib-Tabelle zu schreiben:
import numpy as np
import pandas as pd
import matplotlib.pyplot as plt
fig, ax = plt.subplots()
# hide axes
fig.patch.set_visible(False)
ax.axis('off')
ax.axis('tight')
df = pd.DataFrame(np.random.randn(10, 4), columns=list('ABCD'))
ax.table(cellText=df.values, colLabels=df.columns, loc='center')
fig.tight_layout()
plt.show()
Nicht sicher, ob dies bereits beantwortet wurde, aber wenn Sie nur eine Tabelle in einem Figurenfenster möchten, können Sie die Achsen ausblenden:
fig, ax = plt.subplots()
# Hide axes
ax.xaxis.set_visible(False)
ax.yaxis.set_visible(False)
# Table from Ed Smith answer
clust_data = np.random.random((10,3))
collabel=("col 1", "col 2", "col 3")
ax.table(cellText=clust_data,colLabels=collabel,loc='center')
Du kannst das:
#axs[1].plot(clust_data[:,0],clust_data[:,1]) # Remove this if you don't need it
axs[1].axis("off") # This will leave the table alone in the window