Skip to content

Instantly share code, notes, and snippets.

@spepechen
Last active April 10, 2016 01:50
Show Gist options
  • Save spepechen/9c094248a69f79a7676d to your computer and use it in GitHub Desktop.
Save spepechen/9c094248a69f79a7676d to your computer and use it in GitHub Desktop.
useful #matplotlib tips
######### setting fig size
# Get current size
fig_size = plt.rcParams["figure.figsize"]
# Prints: [8.0, 5.0]
print "Current size:", fig_size
# Set new figure width to 8 and height to 5
fig_size[0] = 8
fig_size[1] = 5
plt.rcParams["figure.figsize"] = fig_size
######### adding only x-axis and y-axis
import matplotlib.pyplot as plt
fig, ax = plt.subplots()
ax.spines['bottom'].set_color('#a1a1a1')
ax.spines['left'].set_color('#a1a1a1')
######### saving img without axises and boarders
fig = plt.imshow(NumpyArray)
plt.axis('off')
figure = plt.gcf() # get current figure
figure.set_size_inches(13.65,3.44) # inches!!!!
fig.axes.get_xaxis().set_visible(False)
fig.axes.get_yaxis().set_visible(False)
plt.savefig('result.png', bbox_inches='tight', pad_inches = 0, dpi = 100 )
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment