Patricio Cubillos

Astronomer


Mostly reminders for myself:

import matplotlib.pyplot as plt
from matplotlib.ticker import MultipleLocator

# Set figure id:
figid = 1
# Set figure size:
figsize = 8,6

f = plt.figure(figid, figsize)
plt.clf()

# Start an axes instance:
# Not defining the position in the canvas:

ax = subplot(111)
# OR Defining the position in the canvas:
# Make a rectangle with x,y coordinates of lowerleft position and
# x,y-length of the area:

rect = [0.125, 0.10, 0.7, 0.8]
ax = plt.axes(rect)

# The position of a colorbar can be defined as well:
cbrect = [0.875, 0.10, 0.035, 0.8]
cax = plt.axes(cbrect)
plt.colorbar(cax=cax)

# Put minor ticks:
# Set minor ticks separation:

mt_separation = 0.05
minorLocator = MultipleLocator(mt_separation)
ax.xaxis.set_minor_locator(minorLocator)

# It works also for the major ticks separation:
Mt_separation = 0.25
ax.xaxis.set_major_locator(MultipleLocator(Mt_separation))
# The major ticks can also be defined in an array:
xticks = np.array([11.0, 11.25, 11.5, 11.75, 12.0])
ax.set_xticks(xticks)

# You can set the label of the ticks with a list of strings:
xtickslabels = ["0.0","0.25","0.5","0.75","1.0"]
ax.set_xticklabels(xtickslabels)

# Set the label of a colorbar:
cax = plt.colorbar()
cax.set_label("Temperature (K)")

# Include an object, with no legend label:
plt.plot(x, y, label="_nolegend_")

# Adjust the lateral and in-between spaces among subplots:
plt.subplots_adjust(left=0.1, right=0.95, bottom=0.04, top=0.99,
hspace=0.13, wspace=0.13)

xticks = plt.getp(ax, 'xticklines')
yticks = plt.getp(ax, 'yticklines')
# adjust markeredgewidth and markersize to adjust the width and length
# of tickmarks:

q = plt.setp(xticks, markeredgewidth=1, markersize=6)
q = plt.setp(yticks, markeredgewidth=1, markersize=6)

# See all the adjustable parameters:
matplotlib.rcParams
# Edit plotting default variables:
matplotlib.rcParams.update({'xtick.minor.size':3.5})
matplotlib.rcParams.update({'ytick.minor.size':3.5})



This site is © Copyright Patricio Cubillos 2014, No Rights Reserved.
Free web templates