本文整理汇总了Python中matplotlib.rc函数的典型用法代码示例。如果您正苦于以下问题:Python rc函数的具体用法?Python rc怎么用?Python rc使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了rc函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: plot_Q_by_year
def plot_Q_by_year(log=False,show=False,save=False,filename=''):
mpl.rc('lines',markersize=6)
fig, (Q2012,Q2013,Q2014,Q2015)=plt.subplots(4)
letter_subplots(fig,0.1,0.95,'top','right','k',font_size=10,font_weight='bold')
for ax in fig.axes:
ax.plot_date(LBJ['Q'].index,LBJ['Q'],ls='-',marker='None',c='k',label='Q FG3')
#ax.plot(LBJstageDischarge.index,LBJstageDischarge['Q-AV(L/sec)'],ls='None',marker='o',color='k')
ax.set_ylim(0,LBJ['Q'].max()+500)
Q2014.axvline(study_start), Q2015.axvline(study_end)
Q2012.set_xlim(start2012,stop2012),Q2013.set_xlim(start2013,stop2013)
Q2014.set_xlim(start2014,stop2014),Q2015.set_xlim(start2015,stop2015)
Q2012.legend(loc='best')
Q2013.set_ylabel('Discharge (Q) L/sec')
#Q2012.set_title("Discharge (Q) L/sec at the Upstream and Downstream Sites, Faga'alu")
for ax in fig.axes:
ax.locator_params(nbins=6,axis='y')
ax.xaxis.set_major_locator(mpl.dates.MonthLocator(interval=2))
ax.xaxis.set_major_formatter(mpl.dates.DateFormatter('%b %Y'))
plt.tight_layout(pad=0.1)
logaxes(log,fig)
show_plot(show,fig)
savefig(save,filename)
return
示例2: test_rcparams
def test_rcparams():
mpl.rc('text', usetex=False)
mpl.rc('lines', linewidth=22)
usetex = mpl.rcParams['text.usetex']
linewidth = mpl.rcParams['lines.linewidth']
fname = os.path.join(os.path.dirname(__file__), 'test_rcparams.rc')
# test context given dictionary
with mpl.rc_context(rc={'text.usetex': not usetex}):
assert mpl.rcParams['text.usetex'] == (not usetex)
assert mpl.rcParams['text.usetex'] == usetex
# test context given filename (mpl.rc sets linewidth to 33)
with mpl.rc_context(fname=fname):
assert mpl.rcParams['lines.linewidth'] == 33
assert mpl.rcParams['lines.linewidth'] == linewidth
# test context given filename and dictionary
with mpl.rc_context(fname=fname, rc={'lines.linewidth': 44}):
assert mpl.rcParams['lines.linewidth'] == 44
assert mpl.rcParams['lines.linewidth'] == linewidth
# test rc_file
mpl.rc_file(fname)
assert mpl.rcParams['lines.linewidth'] == 33
示例3: plot_monthly_average_consumption
def plot_monthly_average_consumption(mpc, country_list, ylabel='normalized', title='', kind='bar', linestyle='-', color='mbygcr', marker='o', linewidth=4.0, fontsize=16, legend=True):
"""
This function plots the yearly data from a monthlypowerconsumptions object
@param df: monthlypowerconsumptions object
@param country_list: country names to add on the title of the plot
@param ylabel: label for y axis
@param title: graphic title
@param kind: graphic type ex: bar or line
@param linestyle: lines style
@param color: color to use
@param marker: shape of point on a line
@param linewidth: line width
@param fontsize: font size
@return: n/a
"""
# Plotting
font = {'family' : 'normal',
'weight' : 'bold',
'size' : 12}
matplotlib.rc('font', **font)
df = mpc.data_normalization(year=False)
df = df.groupby('country').mean()
del df['year']
del df['Sum']
df = df.T
plot_several_countries(df[country_list], ylabel, title, kind=kind, linestyle=linestyle, color=color, marker=marker, linewidth=linewidth, fontsize=fontsize, legend=legend)
示例4: show_plate
def show_plate():
import matplotlib.pyplot as plt
from matplotlib import rc
import daft
plt.rcParams['figure.figsize'] = 14, 8
rc("font", family="serif", size=12)
rc("text", usetex=False)
pgm = daft.PGM(shape=[2.5, 3.5], origin=[0, 0], grid_unit=4,
label_params={'fontsize':18}, observed_style='shaded')
pgm.add_node(daft.Node("lambda", r"$\lambda$", 1, 2.4, scale=2))
pgm.add_node(daft.Node("alpha_0", r"$\alpha_0$", 0.8, 3, scale=2,
fixed=True, offset=(0,10)))
pgm.add_node(daft.Node("lambda_0", r"$\lambda_0$", 1.2, 3, scale=2,
fixed=True, offset=(0,6)))
pgm.add_node(daft.Node("y", r"$y_i$", 1, 1.4, scale=2, observed=True))
pgm.add_plate(daft.Plate([0.5, 0.7, 1, 1.3], label=r"$i \in 1:N$",
shift=-0.1))
pgm.add_edge("alpha_0", "lambda")
pgm.add_edge("lambda_0", "lambda")
pgm.add_edge("lambda", "y")
pgm.render()
plt.show()
示例5: __init__
def __init__(self, parent, messenger=None,
size=(6.00,3.70), dpi=96, **kwds):
self.is_macosx = False
if os.name == 'posix':
if os.uname()[0] == 'Darwin': self.is_macosx = True
matplotlib.rc('axes', axisbelow=True)
matplotlib.rc('lines', linewidth=2)
matplotlib.rc('xtick', labelsize=11, color='k')
matplotlib.rc('ytick', labelsize=11, color='k')
matplotlib.rc('grid', linewidth=0.5, linestyle='-')
self.messenger = messenger
if (messenger is None): self.messenger = self.__def_messenger
self.conf = ImageConfig()
self.cursor_mode='cursor'
self.launch_dir = os.getcwd()
self.mouse_uptime= time.time()
self.last_event_button = None
self.view_lim = (None,None,None,None)
self.zoom_lims = [self.view_lim]
self.old_zoomdc= (None,(0,0),(0,0))
self.parent = parent
self._yfmt = '%.4f'
self._xfmt = '%.4f'
self.figsize = size
self.dpi = dpi
self.__BuildPanel(**kwds)
示例6: _test_determinism_save
def _test_determinism_save(filename, usetex):
# This function is mostly copy&paste from "def test_visibility"
# To require no GUI, we use Figure and FigureCanvasSVG
# instead of plt.figure and fig.savefig
from matplotlib.figure import Figure
from matplotlib.backends.backend_svg import FigureCanvasSVG
from matplotlib import rc
rc('svg', hashsalt='asdf')
rc('text', usetex=usetex)
fig = Figure()
ax = fig.add_subplot(111)
x = np.linspace(0, 4 * np.pi, 50)
y = np.sin(x)
yerr = np.ones_like(y)
a, b, c = ax.errorbar(x, y, yerr=yerr, fmt='ko')
for artist in b:
artist.set_visible(False)
ax.set_title('A string $1+2+\\sigma$')
ax.set_xlabel('A string $1+2+\\sigma$')
ax.set_ylabel('A string $1+2+\\sigma$')
FigureCanvasSVG(fig).print_svg(filename)
示例7: plot_config
def plot_config(filetype='png'):
import matplotlib
# matplotlib.use('pdf')
import matplotlib.pyplot
params = {
'text.usetex': True,
'figure.dpi' : 300,
'savefig.dpi' : 300,
'savefig.format' : filetype,
# 'axes.labelsize': 8, # fontsize for x and y labels (was 10)
# 'axes.titlesize': 8,
# 'text.fontsize': 8, # was 10
# 'legend.fontsize': 8, # was 10
# 'xtick.labelsize': 8,
# 'ytick.labelsize': 8,
# 'figure.figsize': [fig_width,fig_height],
'font.family': 'serif',
'text.latex.preamble': [r'\usepackage[]{siunitx}'
r'\usepackage[]{mhchem}'],
}
matplotlib.rcParams.update(params)
matplotlib.style.use('bmh')
matplotlib.style.use('seaborn-paper')
# matplotlib.style.use('seaborn-dark-palette')
matplotlib.rc('axes', facecolor='white')
matplotlib.rc('grid', linestyle='-', alpha=0.0)
示例8: __get_plot_dict
def __get_plot_dict(plot_style):
"""Define plot styles."""
plot_dict = {
Data.condor_running: ("Jobs running", "#b8c9ec"), # light blue
Data.condor_idle: ("Jobs available", "#fdbe81"), # light orange
Data.vm_requested: ("Slots requested", "#fb8a1c"), # orange
Data.vm_running: ("Slots available", "#2c7bb6"), # blue
Data.vm_draining: ("Slots draining", "#7f69db"), # light blue
}
font = {"family": "sans", "size": 20}
matplotlib.rc("font", **font)
matplotlib.rcParams['pdf.fonttype'] = 42
matplotlib.rcParams['ps.fonttype'] = 42
if plot_style == "slide":
matplotlib.rcParams["figure.figsize"] = 18, 8
matplotlib.rcParams["svg.fonttype"] = "none"
matplotlib.rcParams["path.simplify"] = True
matplotlib.rcParams["path.simplify_threshold"] = 0.5
matplotlib.rcParams["font.sans-serif"] = "Linux Biolinum O"
matplotlib.rcParams["font.family"] = "sans-serif"
matplotlib.rcParams["figure.dpi"] = 300
elif plot_style == "screen":
pass
else:
raise ValueError("Plotting style unknown!")
return plot_dict
示例9: barplot
def barplot(self, filename='', idx=None):
"""
Plot a generic barplot using just the yVars.
idx is the index of the each y-variable to be plotted. if not given, the last value will be used
"""
import numpy
mpl.rc('font',family='sans-serif')
fig = plt.figure()
ax = fig.add_subplot(111)
position = numpy.arange(len(self.yVar),0,-1)
# Reverse in order to go front top to bottom
if not idx:
idx = -1
ax.barh(position, numpy.array([y.data[idx] for y in self.yVar]), align='center', alpha=0.5)
plt.yticks(position, [y.label for y in self.yVar])
# If any labels or titles are explicitly specified, write them
if self.xlabel:
plt.xlabel(self.xlabel)
if self.ylabel:
plt.ylabel(self.ylabel)
if self.title:
plt.title(self.title)
plt.axis('tight')
fig.savefig(filename, bbox_inches='tight')
示例10: plotAvgError
def plotAvgError(p1_win, p1_var,
p2_all_win, p2_all_var,
p2_day_win, p2_day_var, y_max=8):
matplotlib.rc('font', size=18)
width = 2
index = np.arange(0, 7 * width * len(budget_cnts), width * 7)
fig, ax = plt.subplots()
rect1 = ax.bar(index, p1_win, width, color='b', hatch='/')
rect2 = ax.bar(index + width, p1_var, width, color='r', hatch='\\')
rect3 = ax.bar(index + width*2, p2_all_win, width, color='g', hatch='//')
rect4 = ax.bar(index + width*3, p2_all_var, width, color='c', hatch='\\')
rect5 = ax.bar(index + width*4, p2_day_win, width, color='m', hatch='x')
rect6 = ax.bar(index + width*5, p2_day_var, width, color='y', hatch='//')
ax.set_xlim([-3, 7 * width * (len(budget_cnts) + 0.1)])
ax.set_ylim([0, y_max])
ax.set_ylabel('Mean Absolute Error')
ax.set_xlabel('Budget Count')
ax.set_xticks(index + width * 2.5)
ax.set_xticklabels(('0', '5', '10', '20', '25'))
ax.legend((rect1[0], rect2[0], rect3[0], rect4[0], rect5[0], rect6[0]),
('Phase 1 Window', 'Phase 1 Variance',
'Phase 2 H-Window', 'Phase 2 H-Variance',
'Phase 2 D-Window', 'Phase 2 D-Variance'),
ncol=2, fontsize=15)
plt.grid()
plt.savefig('%s_err.eps' % topic, format='eps',
bbox_inches='tight')
示例11: show_cmaps
def show_cmaps(names=None):
"""display all colormaps included in the names list. If names is None, all
defined colormaps will be shown."""
# base code from http://www.scipy.org/Cookbook/Matplotlib/Show_colormaps
matplotlib.rc("text", usetex=False)
a = np.outer(np.arange(0, 1, 0.01), np.ones(10)) # pseudo image data
f = plt.figure(figsize=(10, 5))
f.subplots_adjust(top=0.8, bottom=0.05, left=0.01, right=0.99)
# get list of all colormap names
# this only obtains names of built-in colormaps:
maps = [m for m in cm.datad if not m.endswith("_r")]
# use undocumented cmap_d dictionary instead
maps = [m for m in cm.cmap_d if not m.endswith("_r")]
maps.sort()
# determine number of subplots to make
l = len(maps) + 1
if names is not None:
l = len(names) # assume all names are correct!
# loop over maps and plot the selected ones
i = 0
for m in maps:
if names is None or m in names:
i += 1
ax = plt.subplot(1, l, i)
ax.axis("off")
plt.imshow(a, aspect="auto", cmap=cm.get_cmap(m), origin="lower")
plt.title(m, rotation=90, fontsize=10, verticalalignment="bottom")
plt.savefig("colormaps.png", dpi=100, facecolor="gray")
示例12: update_graph
def update_graph(self):
self.plot.clear()
self.picking_table = {}
iattrs = set()
dattrs = set()
matplotlib.rc('font', **self.canvas_options.fontdict)
# for now, plot everything on the same axis
error_bars = self.canvas_options.show_error_bars
for points, opts in self.pointsets:
if not opts.is_graphed:
continue
points = self.canvas_options.modify_pointset(self,points)
self.picking_table[points.label] = points
opts.plot_with(self, points, self.plot, error_bars)
iattrs.add(points.independent_var_name)
dattrs.add(points.variable_name)
if self.canvas_options.show_axes_labels:
self.plot.set_xlabel(", ".join([i or "" for i in iattrs]),
fontdict=self.canvas_options.fontdict)
self.plot.set_ylabel(", ".join([d or "" for d in dattrs]),
fontdict=self.canvas_options.fontdict)
self.canvas_options.plot_with(self, self.plot)
self.draw()
示例13: __init__
def __init__(self, parent, sz = None):
self._canvas_options = options.PlotCanvasOptions()
matplotlib.rc('font', **self.canvas_options.fontdict)
super(PlotCanvas, self).__init__(parent, wx.ID_ANY, style=wx.RAISED_BORDER)
if not sz:
self.delegate = wxagg.FigureCanvasWxAgg(self, wx.ID_ANY, plt.Figure(facecolor=(0.9,0.9,0.9)))
else:
self.delegate = wxagg.FigureCanvasWxAgg(self, wx.ID_ANY, plt.Figure(facecolor=(0.9, 0.9, 0.9), figsize=sz))
sizer = wx.BoxSizer(wx.HORIZONTAL)
sizer.Add(self.delegate, 1, wx.EXPAND)
self.plot = self.delegate.figure.add_axes([0.1,0.1,0.8,0.8])
self.pointsets = []
self.delegate.figure.canvas.mpl_connect('pick_event', self.on_pick)
self.delegate.figure.canvas.mpl_connect('motion_notify_event', self.on_motion)
# self.figure.canvas.mpl_connect('motion_notify_event',self.on_motion)
self.annotations = {}
# used to index into when there is a pick event
self.picking_table = {}
self.dist_point = None
self.SetSizerAndFit(sizer)
示例14: plotBottleneck
def plotBottleneck(maxGen=None,obs=False,mean=True,color='blue'):
exit()
def plotOne(df, ax, method):
m=df.mean(1)
s=df.std(1)
# plt.locator_params(nbins=4);
m.plot(ax=ax, legend=False, linewidth=3, color=color)
x=m.index.values
m=m.values;s=s.values
ax.fill_between(x, m - 2 * s, m + 2 * s, color=color, alpha=0.3)
ax.set_ylabel(method.strip())
ax.set_ylim([-0.1, ax.get_ylim()[1]])
pplt.setSize(ax)
dfn = \
pd.read_pickle(path + 'nu{}.s{}.df'.format(0.005, 0.0))
fig, ax = plt.subplots(3, 1, sharex=True, figsize=(4, 3), dpi=300)
plotOne(dfn['tajimaD'], ax[0], "Tajima's $D$");
plt.xlabel('Generations')
plotOne(dfn['HAF'], ax[1], "Fay Wu's $H$");
plt.xlabel('Generations')
plotOne(dfn['SFSelect'], ax[2], 'SFSelect');
plt.xlabel('Generations')
plt.gcf().subplots_adjust(bottom=0.25)
mpl.rc('font', **{'family': 'serif', 'serif': ['Computer Modern']});
mpl.rc('text', usetex=True)
pplt.savefig('bottleneck', 300)
plt.show()
示例15: subplot_modes
def subplot_modes(modes):
"""
modes is a list of lists (one for each natural frequency)
each sublist contains 3-comp tuples with (label, freq, mode)
"""
n = len(modes)
print "\nPloting {0} first modes:".format(n)
# initiate plot
fig, axarr = plt.subplots(n, sharex=True)
rc('font', **{'family': 'sans-serif',
'sans-serif': ['Computer Modern Roman']})
# rc('text', usetex=True)
legend_kwargs = {'loc': 'center left', 'bbox_to_anchor': (1, 0.5)}
for i, mode_container in enumerate(modes):
print "\nMode {0}".format(i+1)
legend = map(lambda x: " ".join((x[0], "(f={0:.2f} Hz)".format(x[1]))),
mode_container)
modes_i = map(lambda x: x[2], mode_container)
for j, mode in enumerate(modes_i):
x = np.linspace(0, L, len(mode))
axarr[i].plot(x, mode, style_gen(j, j))
axarr[i].legend(legend, **legend_kwargs)
axarr[i].grid()
axarr[n-1].set_xlabel(r"Length of the beam ($y$ axis) in meters")
axarr[n/2].set_ylabel(r"Normalized deflection")
plt.subplots_adjust(right=0.6)