本文整理汇总了Python中matplotlib.rcdefaults函数的典型用法代码示例。如果您正苦于以下问题:Python rcdefaults函数的具体用法?Python rcdefaults怎么用?Python rcdefaults使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了rcdefaults函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: plot_polar_subplot
def plot_polar_subplot(fig):
#
# Polar demo
#
import pylab
r = arange(0,1,0.001)
theta = 2*2*pi*r
# radar green, solid grid lines
matplotlib.rc('grid', color='#316931', linewidth=1, linestyle='-')
ax = fig.add_subplot(1, 2, 1, polar=True, axisbg='#d5de9c')
ax.plot(theta, r, color='#ee8d18', lw=3)
ax.set_title("And there was much rejoicing!", fontsize=14)
matplotlib.rcdefaults()
#
# First part of the subplot demo
#
def f(t):
return cos(2*pi*t) * exp(-t)
t1 = arange(0.0, 5.0, 0.10)
t2 = arange(0.0, 5.0, 0.02)
A1 = fig.add_subplot(1, 2, 2)
A1.plot(t1, f(t1), 'bo')
A1.plot(t2, f(t2), 'k')
A1.grid(True)
A1.set_title('A tale of one subplot')
A1.set_ylabel('Damped oscillation', fontsize=10)
A1.set_xlabel('time (s)', fontsize=10)
示例2: set_mpl_backend
def set_mpl_backend():
try:
from qtpy import PYQT5
except:
# If Qt isn't available, we don't have to worry about
# setting the backend
return
from matplotlib import rcParams, rcdefaults
# standardize mpl setup
rcdefaults()
if PYQT5:
rcParams['backend'] = 'Qt5Agg'
else:
rcParams['backend'] = 'Qt4Agg'
# The following is a workaround for the fact that Matplotlib checks the
# rcParams at import time, not at run-time. I have opened an issue with
# Matplotlib here: https://github.com/matplotlib/matplotlib/issues/5513
from matplotlib import get_backend
from matplotlib import backends
backends.backend = get_backend()
示例3: plot_curves
def plot_curves(self, freq, data1, label1, limit1, data2, label2, limit2):
matplotlib.rcdefaults()
matplotlib.rcParams['axes.formatter.use_mathtext'] = True
self.figure.clf()
bottom = len(self.cursors) * 0.04 + 0.13
self.figure.subplots_adjust(left = 0.16, bottom = bottom, right = 0.84, top = 0.96)
axes1 = self.figure.add_subplot(111)
axes1.cla()
axes1.xaxis.grid()
axes1.set_xlabel('kHz')
axes1.set_ylabel(label1)
xlim = self.xlim(freq)
axes1.set_xlim(xlim)
if limit1 is not None: axes1.set_ylim(limit1)
self.curve1, = axes1.plot(freq, data1, color = 'blue', label = label1)
self.add_cursors(axes1)
if data2 is None:
self.canvas.draw()
return
axes1.tick_params('y', color = 'blue', labelcolor = 'blue')
axes1.yaxis.label.set_color('blue')
axes2 = axes1.twinx()
axes2.spines['left'].set_color('blue')
axes2.spines['right'].set_color('red')
axes2.set_ylabel(label2)
axes2.set_xlim(xlim)
if limit2 is not None: axes2.set_ylim(limit2)
axes2.tick_params('y', color = 'red', labelcolor = 'red')
axes2.yaxis.label.set_color('red')
self.curve2, = axes2.plot(freq, data2, color = 'red', label = label2)
self.canvas.draw()
示例4: setup_method
def setup_method(self, method):
TestPlotBase.setup_method(self, method)
import matplotlib as mpl
mpl.rcdefaults()
self.ts = tm.makeTimeSeries()
self.ts.name = 'ts'
示例5: plotMovement
def plotMovement(self, parametersFile, targetTranslations, targetRotations):
"""
"""
parameters = numpy.loadtxt(parametersFile)
Vsize = len(parameters)
vols = range(0,Vsize-1)
translations = parameters[1:Vsize,0:3]
rotations = parameters[1:Vsize,3:6]
rotations = rotations / numpy.pi * 180
plotdata = [(translations,'translation (mm)',targetTranslations),
(rotations,'rotation (degree)',targetRotations)
]
for data, ylabel, pngoutput in plotdata:
matplotlib.pyplot.clf()
px, = matplotlib.pyplot.plot(vols, data[:,0])
py, = matplotlib.pyplot.plot(vols, data[:,1])
pz, = matplotlib.pyplot.plot(vols, data[:,2])
matplotlib.pyplot.xlabel('DWI volumes')
matplotlib.pyplot.xlim([0,Vsize+10])
matplotlib.pyplot.ylabel(ylabel)
matplotlib.pyplot.legend([px, py, pz], ['x', 'y', 'z'])
matplotlib.pyplot.savefig(pngoutput)
matplotlib.pyplot.close()
matplotlib.rcdefaults()
示例6: context
def context(style, after_reset=False):
"""Context manager for using style settings temporarily.
Parameters
----------
style : str, dict, or list
A style specification. Valid options are:
+------+-------------------------------------------------------------+
| str | The name of a style or a path/URL to a style file. For a |
| | list of available style names, see `style.available`. |
+------+-------------------------------------------------------------+
| dict | Dictionary with valid key/value pairs for |
| | `matplotlib.rcParams`. |
+------+-------------------------------------------------------------+
| list | A list of style specifiers (str or dict) applied from first |
| | to last in the list. |
+------+-------------------------------------------------------------+
after_reset : bool
If True, apply style after resetting settings to their defaults;
otherwise, apply style on top of the current settings.
"""
with mpl.rc_context():
if after_reset:
mpl.rcdefaults()
use(style)
yield
示例7: set_mpl_defaults
def set_mpl_defaults(defaults=0):
""" Sets defaults for future mpl plots this session
defaults = 0: Normal mpl defaults
= 1: More readable
= 2: Publication setting """
if defaults == 0: # matplotlib defaults
mpl.rcdefaults()
elif defaults == 1:
ax_labelsize = 20
ax_titlesize = 22
tick_labelsize = 'large'
major_tick = dict(size=6, width=1.5, pad=4)
minor_tick = dict(size=3, width=1, pad=4)
lines = dict(linewidth=2.0, markersize=8)
mpl.rc('axes', labelsize=ax_labelsize, titlesize = ax_titlesize)
mpl.rc('xtick', labelsize=tick_labelsize)
mpl.rc('ytick', labelsize=tick_labelsize)
mpl.rc('xtick.major', **major_tick)
mpl.rc('xtick.minor', **minor_tick)
mpl.rc('ytick.major', **major_tick)
mpl.rc('ytick.minor', **minor_tick)
mpl.rc('lines', **lines)
else:
raise ValueError('mpl defaults defaults \'%d\' not recognised' % defaults)
return
示例8: setUp
def setUp(self):
TestPlotBase.setUp(self)
import matplotlib as mpl
mpl.rcdefaults()
self.ts = tm.makeTimeSeries()
self.ts.name = 'ts'
示例9: mpl_init
def mpl_init(fontsize=10):
'''
Initialize Matplotlib rc parameters Pyrocko style.
Returns the matplotlib.pyplot module for convenience.
'''
import matplotlib
matplotlib.rcdefaults()
matplotlib.rc('font', size=fontsize)
matplotlib.rc('axes', linewidth=1.5)
matplotlib.rc('xtick', direction='out')
matplotlib.rc('ytick', direction='out')
ts = fontsize * 0.7071
matplotlib.rc('xtick.major', size=ts, width=0.5, pad=ts)
matplotlib.rc('ytick.major', size=ts, width=0.5, pad=ts)
matplotlib.rc('figure', facecolor='white')
try:
matplotlib.rc('axes', color_cycle=[to01(x) for x in graph_colors])
except KeyError:
pass
from matplotlib import pyplot as plt
return plt
示例10: __enter__
def __enter__(self):
"""
Set matplotlib defaults.
"""
from matplotlib import get_backend, rcParams, rcdefaults
import locale
try:
locale.setlocale(locale.LC_ALL, str('en_US.UTF-8'))
except:
try:
locale.setlocale(locale.LC_ALL,
str('English_United States.1252'))
except:
msg = "Could not set locale to English/United States. " + \
"Some date-related tests may fail"
warnings.warn(msg)
if get_backend().upper() != 'AGG':
import matplotlib
try:
matplotlib.use('AGG', warn=False)
except TypeError:
msg = "Image comparison requires matplotlib backend 'AGG'"
warnings.warn(msg)
# set matplotlib builtin default settings for testing
rcdefaults()
rcParams['font.family'] = 'Bitstream Vera Sans'
rcParams['text.hinting'] = False
try:
rcParams['text.hinting_factor'] = 8
except KeyError:
warnings.warn("could not set rcParams['text.hinting_factor']")
return self
示例11: setup
def setup():
# The baseline images are created in this locale, so we should use
# it during all of the tests.
import locale
import warnings
from matplotlib.backends import backend_agg, backend_pdf, backend_svg
try:
locale.setlocale(locale.LC_ALL, str("en_US.UTF-8"))
except locale.Error:
try:
locale.setlocale(locale.LC_ALL, str("English_United States.1252"))
except locale.Error:
warnings.warn("Could not set locale to English/United States. " "Some date-related tests may fail")
use("Agg", warn=False) # use Agg backend for these tests
# These settings *must* be hardcoded for running the comparison
# tests and are not necessarily the default values as specified in
# rcsetup.py
rcdefaults() # Start with all defaults
rcParams["font.family"] = "Bitstream Vera Sans"
rcParams["text.hinting"] = False
rcParams["text.hinting_factor"] = 8
# Clear the font caches. Otherwise, the hinting mode can travel
# from one test to another.
backend_agg.RendererAgg._fontd.clear()
backend_pdf.RendererPdf.truetype_font_cache.clear()
backend_svg.RendererSVG.fontd.clear()
示例12: setup
def setup():
# The baseline images are created in this locale, so we should use
# it during all of the tests.
import locale
import warnings
from matplotlib.backends import backend_agg, backend_pdf, backend_svg
try:
locale.setlocale(locale.LC_ALL, str('en_US.UTF-8'))
except locale.Error:
try:
locale.setlocale(locale.LC_ALL, str('English_United States.1252'))
except locale.Error:
warnings.warn(
"Could not set locale to English/United States. "
"Some date-related tests may fail")
use('Agg', warn=False) # use Agg backend for these tests
# These settings *must* be hardcoded for running the comparison
# tests and are not necessarily the default values as specified in
# rcsetup.py
rcdefaults() # Start with all defaults
set_font_settings_for_testing()
示例13: _setup
def _setup():
# The baseline images are created in this locale, so we should use
# it during all of the tests.
try:
locale.setlocale(locale.LC_ALL, str('en_US.UTF-8'))
except locale.Error:
try:
locale.setlocale(locale.LC_ALL, str('English_United States.1252'))
except locale.Error:
warnings.warn(
"Could not set locale to English/United States. "
"Some date-related tests may fail")
plt.switch_backend('Agg') # use Agg backend for these test
if mpl.get_backend().lower() != "agg":
msg = ("Using a wrong matplotlib backend ({0}), "
"which will not produce proper images")
raise Exception(msg.format(mpl.get_backend()))
# These settings *must* be hardcoded for running the comparison
# tests
mpl.rcdefaults() # Start with all defaults
mpl.rcParams['text.hinting'] = True
mpl.rcParams['text.antialiased'] = True
mpl.rcParams['text.hinting_factor'] = 8
# make sure we don't carry over bad plots from former tests
msg = ("no of open figs: {} -> find the last test with ' "
"python tests.py -v' and add a '@cleanup' decorator.")
assert len(plt.get_fignums()) == 0, msg.format(plt.get_fignums())
示例14: analyse_sign_frame_size_fluctuations
def analyse_sign_frame_size_fluctuations(annotation_path, output_file):
with open(output_file, 'w') as outp:
raw_data = pd.read_csv(annotation_path, delimiter=';')
outp.write("Analyse frame size fluctuations.\n")
data = pd.DataFrame()
data['width'] = raw_data['Lower right corner X'] - raw_data['Upper left corner X']
data['height'] = raw_data['Lower right corner Y'] - raw_data['Upper left corner Y']
outp.write("Minimum width = {}, minimum height = {}\n".format(data['width'].min(), data['height'].min()))
outp.write("Maximum width = {}, maximum height = {}\n".format(data['width'].max(), data['height'].max()))
matplotlib.rcdefaults()
matplotlib.rcParams['font.family'] = 'fantasy'
matplotlib.rcParams['font.fantasy'] = 'Times New Roman', 'Ubuntu', 'Arial', 'Tahoma', 'Calibri'
matplotlib.rcParams.update({'font.size': 18})
hist, bins = np.histogram(data['width'], bins=range(data['width'].min(), data['width'].max(), 5))
width = 0.7 * (bins[1] - bins[0])
center = (bins[:-1] + bins[1:]) / 2
plt.bar(center, hist, align='center', width=width)
plt.title("Ширина дорожных знаков")
plt.xlabel("Ширина")
plt.ylabel("Сколько раз встречалась")
plt.xticks(bins, bins)
plt.show()
hist, bins = np.histogram(data['height'], bins=range(data['width'].min(), data['width'].max(), 5))
width = 0.7 * (bins[1] - bins[0])
center = (bins[:-1] + bins[1:]) / 2
plt.bar(center, hist, align='center', width=width)
plt.title("Высота дорожных знаков")
plt.xlabel("Высота")
plt.ylabel("Сколько раз встречалась")
plt.xticks(bins, bins)
plt.show()
示例15: wind_dir_pressure
def wind_dir_pressure(year=2013):
from statsmodels.nonparametric.kernel_density import KDEMultivariate as KDE
import robust as rb
min2 = 0
sigfac = 3
sigsamp = 5
d = get_data(year=year)
wdir = d["winddir_deg"]
wdir_rand = wdir + np.random.normal(0,12,len(wdir))
bad = np.isnan(wdir_rand)
wdir_rand[bad] = np.random.uniform(0,360,np.sum(bad))
press = d["pressure"]
dist1 = wdir_rand
dist2 = press
med1 = np.median(dist1)
sig1 = rb.std(dist1)
datamin1 = np.min(dist1)
datamax1 = np.max(dist1)
min1 = 0.0
max1 = 360.0
med2 = np.median(dist2)
sig2 = rb.std(dist2)
datamin2 = np.min(dist2)
datamax2 = np.max(dist2)
min2 = np.min(dist2)
max2 = np.max(dist2)
X, Y = np.mgrid[min1:max1:100j, min2:max2:100j]
positions = np.vstack([X.ravel(), Y.ravel()])
values = np.vstack([dist1, dist2])
kernel = KDE(values,var_type='cc',bw=[sig1/sigsamp,sig2/sigsamp])
Z = np.reshape(kernel.pdf(positions).T, X.shape)
aspect = (max1-min1)/(max2-min2) * 8.5/11.0
plot_params()
plt.ion()
plt.figure(5,figsize=(11,8.5))
plt.clf()
ax = plt.subplot(111)
ax.imshow(np.rot90(Z), cmap=plt.cm.CMRmap_r,aspect=aspect, \
extent=[min1, max1, min2, max2],origin='upper')
ax.yaxis.labelpad = 12
ax.set_ylabel('Atmospheric Pressure (in-Hg)',fontsize=fs)
ax.set_xlabel('Wind Direction (degrees)',fontsize=fs)
plt.title('Wind Direction and Pressure at Thacher Observatory in '+str(year),fontsize=fs)
plt.savefig('Wind_Direction_Pressure_'+str(year)+'.png',dpi=300)
mpl.rcdefaults()
return