[英]How to shift table location using .plot(table = True) for Matplotlib
目前我正在使用 .plot(table=True) 來顯示表格,這是我當前的輸出:
我可以知道如何將桌子向下移動嗎?
這是我的代碼:
import matplotlib.pyplot as plt
import pandas as pd
import seaborn as sns
import numpy as np
sns.set()
df = pd.read_csv('file.csv')
df['year'] = pd.DatetimeIndex(df['month']).year
df.head()
ax = df.groupby(['year', 'child_gender'])['birth_count'].count().unstack('child_gender').fillna(0).plot(
kind='line',
stacked=False,
marker='o',
table = True)
plt.xticks(np.arange(2016,2019,1))
plt.legend(title='Child Gender', bbox_to_anchor=(1.0, 1), loc='upper left')
plt.ylabel('Birth Count')
plt.xlabel('Year')
plt.title("Total Birth Count By Child Gender")
plt.autoscale(enable=False)
plt.tight_layout()
plt.show()
這是我擁有的當前數據框:
不要使用 table=True,而是使用 plt.table 在繪圖下創建一個表
fig, ax = plt.subplots(figsize=(5,8))
df.plot(ax=ax)
plt.table(cellText=df.values,
loc='center left',
rowLabels=['f','m'],
colLabels=['2016','2017','2018'],
bbox=[0.0, -0.2, 1, 0.1])
使用 bbox 列表中的第二個值,您可以隨意移動它
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.