1
私は、左右にテキストを正しく整列させるのに苦労しています。同じCOL幅は、右/左中央/のために使用されている:Matplotlib Textテーブル内の整列
- Center aligned:正しく中心に、OK
- Left aligned:でも、テーブルの引数としてColWidthsプロパティを省略して遊んで左
- に無駄なスペース私のお気に入りのソリューションthe_table._autoColumns = range(-1、len(colLabels))は状況を改善しない
私は間違っていますか?これはmatplotlibのバグですか?
よろしく、
import pandas as pd
import matplotlib.pyplot as plt
size_x, size_y = 12, 4
fig = plt.figure (figsize=(size_x, size_y))
ax = fig.add_subplot(111)
col_ID = pd.Series ([ "R001", "R002", "R003", "R005", "R006", "R007" ])
col_Title = pd.Series ([ 50*"*", 10*"-", 70*"x", "R005", "R006", "R007" ])
col_x = pd.Series ([ 3, 1, 3, 4, 2, 3 ])
col_y = pd.Series ([ 4, 2, 3, 2, 4, 3 ])
legend_df = pd.DataFrame ({ "ID" : col_ID,
"Title" : col_Title,
"X-Pos" : col_x,
"Y-Pos" : col_y,
"Value" : col_x * col_y })
rowLabels = legend_df.index
colLabels = legend_df.columns
cellText = legend_df.values
# Center-Aligned text looks ok
the_table = plt.table (cellText=cellText, rowLabels=rowLabels, colLabels=colLabels, loc='upper center', cellLoc="center", colWidths=[0.05, 0.52, 0.05, 0.05, 0.05, 0.05])
# Bogus: Same colWidths, but left OR right aligned -> unwanted space in title column
# the_table = ax.table (cellText=cellText, rowLabels=rowLabels, colLabels=colLabels, loc='upper center', cellLoc="left", colWidths=[0.05, 0.52, 0.05, 0.05, 0.05, 0.05])
the_table.auto_set_font_size(False)
the_table.set_fontsize (8)
# Set col width automatically
# the_table._autoColumns = range (-1,len (colLabels))
ax.xaxis.set_visible (False) # Grafik-Achsen ausschalten, wir wollen nur Plot
ax.yaxis.set_visible (False)
# the_table.scale(2, 2)
plt.show()
迅速な対応をありがとう。パディング値を列幅ではなくフォントサイズに依存させる方が良いでしょうか? –
テーブルクラスがmatplotlibに書き込まれる方法は、パディングをフォントサイズに依存するように変更する方法はありません。もちろん、テーブルクラスとセルクラスのサブクラス化とそれぞれのメソッドの再実装は別です。このデザインの選択について私の意見を聞いていますか? – ImportanceOfBeingErnest
matplotlibのバグを開く価値はあるのでしょうか?私の視点からは、あなたの解決策は存在しますが、ユーザーが実装の内部を調整する必要がないように、正常なデフォルト/アルゴリズムが存在するはずです。あなたの意見は何ですか? –