Ryan's Blog

Matplotlib: using scientific notation in tick values

Posted in Uncategorized by ryanlayer on January 8, 2015


formatter = matplotlib.ticker.ScalarFormatter()
formatter.set_powerlimits((-3,4))
ax.xaxis.set_major_formatter(formatter)

Tagged with: ,

Matplotlib: Set Font

Posted in Uncategorized by ryanlayer on April 22, 2014

from matplotlib import rcParams
rcParams['font.family'] = 'Arial'

Tagged with: ,

Matplotlib: black background

Posted in research by ryanlayer on February 18, 2014


matplotlib.rcParams.update({'font.size': 12})
fig = matplotlib.pyplot.figure(figsize=(5,5),dpi=300,facecolor='black')
fig.subplots_adjust(wspace=.05,left=.01,bottom=.01)
ax = fig.add_subplot(1,1,1,axisbg='k')

ax.spines['top'].set_visible(False)
ax.spines['right'].set_visible(False)
ax.spines['bottom'].set_linewidth(0.5)
ax.spines['left'].set_linewidth(0.5)
ax.spines['bottom'].set_color('white')
ax.spines['left'].set_color('white')

ax.title.set_color('white')
ax.yaxis.label.set_color('white')
ax.xaxis.label.set_color('white')
ax.tick_params(axis='x', colors='white')
ax.tick_params(axis='y', colors='white')

ax.tick_params(axis='both', direction='in')
ax.get_xaxis().tick_bottom()
ax.get_yaxis().tick_left()

ax.set_xlabel('X-Axis Label Here')
ax.set_ylabel('Y-Axis Label Here')
ax.set_title('Title Here')

ax.plot(range(10),range(10),'.-',color='yellow',\
  linewidth=2,\
  markersize=12)

matplotlib.pyplot.savefig("dark.png",\
  bbox_inches='tight',\
  facecolor=fig.get_facecolor(),\
  transparent=True)

Here for a Matplotlib color names.

Tagged with: , ,

Matplotlib: plot border, removing and setting width

Posted in Uncategorized by ryanlayer on December 17, 2013
ax.spines['top'].set_visible(False)
ax.spines['right'].set_visible(False)
ax.spines['bottom'].set_linewidth(0.5)
ax.spines['left'].set_linewidth(0.5)
Tagged with: ,

Matplotlib: axis labels, rotating and aligning

Posted in Uncategorized by ryanlayer on December 17, 2013
n=5

x = np.arange(n)
y = np.sin(np.linspace(-3,3,n))
xlabels = ['Ticklabel %i' % i for i in range(n)]

fig, axs = plt.subplots(1,3, figsize=(12,3))

ha = ['right', 'center', 'left']

for n, ax in enumerate(axs):
    ax.plot(x,y, 'o-')
    ax.set_title(ha[n])
    ax.set_xticks(x)
    ax.set_xticklabels(xlabels, rotation=40, ha=ha[n])

 

http://stackoverflow.com/questions/14852821/aligning-rotated-xticklabels-with-their-respective-xticks

Tagged with: , ,