0

Given the following table (borrowed from here):

import numpy as np
import pandas as pd
import matplotlib.pyplot as plt

fig, ax = plt.subplots()

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()

I want to hide all lines save for those horizontal under each row (but not the bottom or top 2 rows). Is this level of control attainable? I tried ax.hlines, but the lines seemed to plot randomly.

Dance Party
  • 3,459
  • 10
  • 42
  • 67

1 Answers1

0

I am not sure about the "but not the bottom or top 2 rows", can you specify?

Yet, to get only the horizontal lines, you can add the edges='horizontal' parameter:

ax.table(cellText=df.values, colLabels=df.columns, loc='center', edges='horizontal')

output: horizontal lines

mozway
  • 194,879
  • 13
  • 39
  • 75