Remove whitespace from matplotlib heatplot

Tim

I have a heatplot in matplotlib for which I want to remove the whitespace to the north and east of the plot, as shown in the image below. enter image description here

here is the code I'm using to generate the plots:

# plotting
figsize=(50,20)
y,x = 1,2
fig, axarry = plt.subplots(y,x, figsize=figsize)
p = axarry[1].pcolormesh(copy_matrix.values)

# put the major ticks at the middle of each cell
axarry[1].set_xticks(np.arange(copy_matrix.shape[1])+0.5, minor=False)
axarry[1].set_yticks(np.arange(copy_matrix.shape[0])+0.5, minor=False)

axarry[1].set_title(file_name, fontweight='bold')

axarry[1].set_xticklabels(copy_matrix.columns, rotation=90)
axarry[1].set_yticklabels(copy_matrix.index)

fig.colorbar(p, ax=axarry[1])

Phylo.draw(tree, axes=axarry[0])
Joe Kington

The easiest way to do this is to use ax.axis('tight').

By default, matplotlib tries to choose "even" numbers for the axes limits. If you want the plot to be scaled to the strict limits of your data, use ax.axis('tight'). ax.axis('image') is similar, but will also make the cells of your "heatmap" square.

For example:

import numpy as np
import matplotlib.pyplot as plt

# Note the non-"even" size... (not a multiple of 2, 5, or 10)
data = np.random.random((73, 78))

fig, axes = plt.subplots(ncols=3)
for ax, title in zip(axes, ['Default', 'axis("tight")', 'axis("image")']):
    ax.pcolormesh(data)
    ax.set(title=title)

axes[1].axis('tight')
axes[2].axis('image')

plt.show()

enter image description here

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

Remove whitespace from matplotlib heatplot

From Dev

Remove whitespace from QTextEdit

From Dev

Remove whitespace from SVG

From Java

Remove all whitespace from string

From Dev

Remove whitespace from part of a string

From Dev

how to remove whitespace from explode

From Dev

how to remove whitespace from explode

From Dev

Remove empty or whitespace strings from array - Javascript

From Dev

Remove Insignificant Whitespace From Xml Document

From Java

Efficient way to remove ALL whitespace from String?

From Dev

Postgresql - remove any whitespace from sub string

From Dev

How to remove whitespace from string in Ruby

From Dev

Remove whitespace from highcharts gauge chart?

From Dev

PHP - Unable to remove whitespace from string

From Dev

Remove shortest leading whitespace from all lines

From Dev

How to remove whitespace from end of string in Python?

From Dev

Remove whitespace from an argument into a JS function

From Dev

Remove special characters from a string except whitespace

From Dev

Remove unnecessary whitespace from Jinja rendered template

From Dev

How to remove whitespace from a div/container

From Dev

How to remove extra whitespace from image in opencv?

From Dev

How to remove whitespace from an image in OpenCV?

From Dev

Remove whitespace from json using jackson

From Dev

Remove whitespace from all array elements

From Dev

Remove Insignificant Whitespace From Xml Document

From Dev

PHP - Unable to remove whitespace from string

From Dev

MySQL remove Whitespace from fields (NOT using TRIM)

From Dev

Python: How to remove whitespace from number in a string

From Dev

Remove whitespace from text while preserving newlines

Related Related

HotTag

Archive