Reputation: 73
I'm currently trying to visualize a matrix in Python using Matplotlib, however, the problem is that the number of columns, is much greater than the number of rows, so when i visualize it, the y-axis becomes small, as seen on the following figure.
The matrix is a pandas DataFrame with 23 rows and 1880 columns. I've tried to visualize it with imshow()
and matshow
, but both methods scales the picture awkwardly. I've also attempted tight_layout()
but it doesn't really change anything.
Is there anything I can do to scale the plot?
Here is the code i'm using for plotting:
plt.figure()
ax = plt.gca()
plt.imshow(df.drop(["column2"], axis=1).transpose(), cmap='hot', interpolation='nearest')
plt.savefig("Test.pdf")
Upvotes: 0
Views: 198
Reputation: 2615
imshow knows an aspect
keyword argument which you can set to auto
to do this:
plt.imshow(... , aspect='auto')
Upvotes: 1
Reputation: 1653
I found a good aspect ratio using the pcolor
function. Your code snippet would become:
plt.pcolor(df.drop(["column2"], axis=1).transpose(), cmap='hot')
plt.savefig("Test.pdf")
Unfortunately, the interpolation keyword is not supported and I don't know if you need it. This is the result I obtain with some random data:
Upvotes: 1