Skip to content

Instantly share code, notes, and snippets.

@neurojojo
Created July 31, 2020 02:29
Show Gist options
  • Save neurojojo/ceabb04a6ebd777e4923ec206f74df01 to your computer and use it in GitHub Desktop.
Save neurojojo/ceabb04a6ebd777e4923ec206f74df01 to your computer and use it in GitHub Desktop.
Create readable figures in Python
import matplotlib.pyplot as plt
x=[-2,-1,0,1,2]; y=[4,1,0,1,4]
# Set DPI >=150 for readability and adjust figsize
myfig = plt.figure( figsize=(3,1.5), dpi=150 )
# Pick a nice color, make sure your markers are large and
# make sure your lines are wide
myplt = plt.plot( x, y, 'o', color = 'c', markersize=6)
plt.plot( x, y, color= 'c', linewidth=2)
# Adjust y-limits
myfig.axes[0].set_ylim(-1,5)
# Get rid of the box around your plot
myfig.axes[0].spines['top'].set_visible(False)
myfig.axes[0].spines['right'].set_visible(False)
plt.tight_layout() # To ensure everything fits
plt.savefig('myfig.png',dpi=150) # Set DPI
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment