我试图找到一种方法来使Pandas DataFrame绘图表的行高适合其内容。如果不可能,有没有其他方法来绘制这种情节?
import pandas as pd
import matplotlib.pyplot as plt
import numpy as np
%matplotlib inline
fig, ax = plt.subplots(1, 1,figsize =(8,2))
df = pd.DataFrame(np.round(np.random.rand(5, 3),2), columns=['a', 'b', 'c'],index=['1\na','2\na','3\na','4\na','5\na'])
ax.get_xaxis().set_visible(False) # Hide Ticks
df.plot(table=True, ax=ax)
fig.dpi = 600
答案 0 :(得分:0)
只需删除所有" \ na"在您的Dataframe索引列表中,您的问题应该得到解决。
import pandas as pd
import matplotlib.pyplot as plt
import numpy as np
%matplotlib inline
fig, ax = plt.subplots(1, 1,figsize =(8,2))
df = pd.DataFrame(np.round(np.random.rand(5, 3),2), columns=['a', 'b', 'c'],index=['1','2','3','4','5'])
ax.get_xaxis().set_visible(False) # Hide Ticks
df.plot(table=True, ax=ax)
fig.dpi = 600