Python matplotlib.rc() Examples
The following are 30 code examples for showing how to use matplotlib.rc(). These examples are extracted from open source projects. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example.
You may check out the related API usage on the sidebar.
You may also want to check out all available functions/classes of the module
matplotlib
, or try the search function
.
Example 1
Project: pruning_yolov3 Author: zbyuan File: utils.py License: GNU General Public License v3.0 | 6 votes |
def plot_evolution_results(hyp): # from utils.utils import *; plot_evolution_results(hyp) # Plot hyperparameter evolution results in evolve.txt x = np.loadtxt('evolve.txt', ndmin=2) f = fitness(x) weights = (f - f.min()) ** 2 # for weighted results fig = plt.figure(figsize=(12, 10)) matplotlib.rc('font', **{'size': 8}) for i, (k, v) in enumerate(hyp.items()): y = x[:, i + 5] # mu = (y * weights).sum() / weights.sum() # best weighted result mu = y[f.argmax()] # best single result plt.subplot(4, 5, i + 1) plt.plot(mu, f.max(), 'o', markersize=10) plt.plot(y, f, '.') plt.title('%s = %.3g' % (k, mu), fontdict={'size': 9}) # limit to 40 characters print('%15s: %.3g' % (k, mu)) fig.tight_layout() plt.savefig('evolve.png', dpi=200)
Example 2
Project: Computable Author: ktraunmueller File: pyplot.py License: MIT License | 6 votes |
def subplots_adjust(*args, **kwargs): """ Tune the subplot layout. call signature:: subplots_adjust(left=None, bottom=None, right=None, top=None, wspace=None, hspace=None) The parameter meanings (and suggested defaults) are:: left = 0.125 # the left side of the subplots of the figure right = 0.9 # the right side of the subplots of the figure bottom = 0.1 # the bottom of the subplots of the figure top = 0.9 # the top of the subplots of the figure wspace = 0.2 # the amount of width reserved for blank space between subplots hspace = 0.2 # the amount of height reserved for white space between subplots The actual defaults are controlled by the rc file """ fig = gcf() fig.subplots_adjust(*args, **kwargs) draw_if_interactive()
Example 3
Project: Computable Author: ktraunmueller File: pyplot.py License: MIT License | 6 votes |
def set_cmap(cmap): """ Set the default colormap. Applies to the current image if any. See help(colormaps) for more information. *cmap* must be a :class:`~matplotlib.colors.Colormap` instance, or the name of a registered colormap. See :func:`matplotlib.cm.register_cmap` and :func:`matplotlib.cm.get_cmap`. """ cmap = cm.get_cmap(cmap) rc('image', cmap=cmap.name) im = gci() if im is not None: im.set_cmap(cmap) draw_if_interactive()
Example 4
Project: Ensemble-Bayesian-Optimization Author: zi-w File: simple_functions.py License: MIT License | 6 votes |
def plot_f(f, filenm='test_function.eps'): # only for 2D functions import matplotlib.pyplot as plt import matplotlib font = {'size': 20} matplotlib.rc('font', **font) delta = 0.005 x = np.arange(0.0, 1.0, delta) y = np.arange(0.0, 1.0, delta) nx = len(x) X, Y = np.meshgrid(x, y) xx = np.array((X.ravel(), Y.ravel())).T yy = f(xx) plt.figure() plt.contourf(X, Y, yy.reshape(nx, nx), levels=np.linspace(yy.min(), yy.max(), 40)) plt.xlim([0, 1]) plt.ylim([0, 1]) plt.colorbar() plt.scatter(f.argmax[0], f.argmax[1], s=180, color='k', marker='+') plt.savefig(filenm)
Example 5
Project: matplotlib-4-abaqus Author: Solid-Mechanics File: pyplot.py License: MIT License | 6 votes |
def subplots_adjust(*args, **kwargs): """ Tune the subplot layout. call signature:: subplots_adjust(left=None, bottom=None, right=None, top=None, wspace=None, hspace=None) The parameter meanings (and suggested defaults) are:: left = 0.125 # the left side of the subplots of the figure right = 0.9 # the right side of the subplots of the figure bottom = 0.1 # the bottom of the subplots of the figure top = 0.9 # the top of the subplots of the figure wspace = 0.2 # the amount of width reserved for blank space between subplots hspace = 0.2 # the amount of height reserved for white space between subplots The actual defaults are controlled by the rc file """ fig = gcf() fig.subplots_adjust(*args, **kwargs) draw_if_interactive()
Example 6
Project: matplotlib-4-abaqus Author: Solid-Mechanics File: pyplot.py License: MIT License | 6 votes |
def set_cmap(cmap): """ Set the default colormap. Applies to the current image if any. See help(colormaps) for more information. *cmap* must be a :class:`~matplotlib.colors.Colormap` instance, or the name of a registered colormap. See :func:`matplotlib.cm.register_cmap` and :func:`matplotlib.cm.get_cmap`. """ cmap = cm.get_cmap(cmap) rc('image', cmap=cmap.name) im = gci() if im is not None: im.set_cmap(cmap) draw_if_interactive()
Example 7
Project: big-discriminator-batch-spoofing-gan Author: akanimax File: generate_fid_plot.py License: MIT License | 6 votes |
def generate_plot(x, y, title, save_path): """ generates the plot given the indices and fid values :param x: the indices (epochs) :param y: fid values :param title: title of the generated plot :param save_path: path to save the file :return: None (saves file) """ font = {'family': 'normal', 'size': 20} matplotlib.rc('font', **font) plt.figure(figsize=(10, 6)) annot_min(x, y) plt.margins(.05, .05) plt.title(title) plt.xlabel("Epochs") plt.ylabel("FID scores") plt.plot(x, y, linewidth=4) plt.tight_layout() plt.savefig(save_path, bbox_inches='tight')
Example 8
Project: big-discriminator-batch-spoofing-gan Author: akanimax File: generate_is_plot.py License: MIT License | 6 votes |
def generate_plot(x, y, title, save_path): """ generates the plot given the indices and is values :param x: the indices (epochs) :param y: IS values :param title: title of the generated plot :param save_path: path to save the file :return: None (saves file) """ font = {'family': 'normal', 'size': 20} matplotlib.rc('font', **font) plt.figure(figsize=(10, 6)) annot_max(x, y) plt.margins(.05, .05) plt.title(title) plt.xlabel("Epochs") plt.ylabel("Inception scores") plt.ylim(0, max(y) + 2) plt.plot(x, y, linewidth=4) plt.tight_layout() plt.savefig(save_path, bbox_inches='tight')
Example 9
Project: neural-network-animation Author: miloharper File: test_rcparams.py License: MIT License | 6 votes |
def test_rcparams(): usetex = mpl.rcParams['text.usetex'] linewidth = mpl.rcParams['lines.linewidth'] # 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 linewdith 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 try: mpl.rc_file(fname) assert mpl.rcParams['lines.linewidth'] == 33 finally: mpl.rcParams['lines.linewidth'] = linewidth
Example 10
Project: neural-network-animation Author: miloharper File: test_rcparams.py License: MIT License | 6 votes |
def test_rcparams_update(): if sys.version_info[:2] < (2, 7): raise nose.SkipTest("assert_raises as context manager " "not supported with Python < 2.7") rc = mpl.RcParams({'figure.figsize': (3.5, 42)}) bad_dict = {'figure.figsize': (3.5, 42, 1)} # make sure validation happens on input with assert_raises(ValueError): with warnings.catch_warnings(): warnings.filterwarnings('ignore', message='.*(validate)', category=UserWarning) rc.update(bad_dict) # remove know failure + warnings after merging to master
Example 11
Project: neural-network-animation Author: miloharper File: test_rcparams.py License: MIT License | 6 votes |
def test_rcparams_reset_after_fail(): # There was previously a bug that meant that if rc_context failed and # raised an exception due to issues in the supplied rc parameters, the # global rc parameters were left in a modified state. if sys.version_info[:2] >= (2, 7): from collections import OrderedDict else: raise SkipTest("Test can only be run in Python >= 2.7 as it requires OrderedDict") with mpl.rc_context(rc={'text.usetex': False}): assert mpl.rcParams['text.usetex'] is False with assert_raises(KeyError): with mpl.rc_context(rc=OrderedDict([('text.usetex', True),('test.blah', True)])): pass assert mpl.rcParams['text.usetex'] is False
Example 12
Project: neural-network-animation Author: miloharper File: pyplot.py License: MIT License | 6 votes |
def subplots_adjust(*args, **kwargs): """ Tune the subplot layout. call signature:: subplots_adjust(left=None, bottom=None, right=None, top=None, wspace=None, hspace=None) The parameter meanings (and suggested defaults) are:: left = 0.125 # the left side of the subplots of the figure right = 0.9 # the right side of the subplots of the figure bottom = 0.1 # the bottom of the subplots of the figure top = 0.9 # the top of the subplots of the figure wspace = 0.2 # the amount of width reserved for blank space between subplots hspace = 0.2 # the amount of height reserved for white space between subplots The actual defaults are controlled by the rc file """ fig = gcf() fig.subplots_adjust(*args, **kwargs) draw_if_interactive()
Example 13
Project: neural-network-animation Author: miloharper File: pyplot.py License: MIT License | 6 votes |
def set_cmap(cmap): """ Set the default colormap. Applies to the current image if any. See help(colormaps) for more information. *cmap* must be a :class:`~matplotlib.colors.Colormap` instance, or the name of a registered colormap. See :func:`matplotlib.cm.register_cmap` and :func:`matplotlib.cm.get_cmap`. """ cmap = cm.get_cmap(cmap) rc('image', cmap=cmap.name) im = gci() if im is not None: im.set_cmap(cmap) draw_if_interactive()
Example 14
Project: GraphicDesignPatternByPython Author: Relph1119 File: pyplot.py License: MIT License | 6 votes |
def subplots_adjust(left=None, bottom=None, right=None, top=None, wspace=None, hspace=None): """ Tune the subplot layout. The parameter meanings (and suggested defaults) are:: left = 0.125 # the left side of the subplots of the figure right = 0.9 # the right side of the subplots of the figure bottom = 0.1 # the bottom of the subplots of the figure top = 0.9 # the top of the subplots of the figure wspace = 0.2 # the amount of width reserved for space between subplots, # expressed as a fraction of the average axis width hspace = 0.2 # the amount of height reserved for space between subplots, # expressed as a fraction of the average axis height The actual defaults are controlled by the rc file """ fig = gcf() fig.subplots_adjust(left, bottom, right, top, wspace, hspace)
Example 15
Project: GraphicDesignPatternByPython Author: Relph1119 File: pyplot.py License: MIT License | 6 votes |
def set_cmap(cmap): """ Set the default colormap. Applies to the current image if any. See help(colormaps) for more information. *cmap* must be a :class:`~matplotlib.colors.Colormap` instance, or the name of a registered colormap. See :func:`matplotlib.cm.register_cmap` and :func:`matplotlib.cm.get_cmap`. """ cmap = cm.get_cmap(cmap) rc('image', cmap=cmap.name) im = gci() if im is not None: im.set_cmap(cmap)
Example 16
Project: recruit Author: Frank-qlu File: common.py License: Apache License 2.0 | 5 votes |
def _check_grid_settings(self, obj, kinds, kws={}): # Make sure plot defaults to rcParams['axes.grid'] setting, GH 9792 import matplotlib as mpl def is_grid_on(): xoff = all(not g.gridOn for g in self.plt.gca().xaxis.get_major_ticks()) yoff = all(not g.gridOn for g in self.plt.gca().yaxis.get_major_ticks()) return not (xoff and yoff) spndx = 1 for kind in kinds: if not _ok_for_gaussian_kde(kind): continue self.plt.subplot(1, 4 * len(kinds), spndx) spndx += 1 mpl.rc('axes', grid=False) obj.plot(kind=kind, **kws) assert not is_grid_on() self.plt.subplot(1, 4 * len(kinds), spndx) spndx += 1 mpl.rc('axes', grid=True) obj.plot(kind=kind, grid=False, **kws) assert not is_grid_on() if kind != 'pie': self.plt.subplot(1, 4 * len(kinds), spndx) spndx += 1 mpl.rc('axes', grid=True) obj.plot(kind=kind, **kws) assert is_grid_on() self.plt.subplot(1, 4 * len(kinds), spndx) spndx += 1 mpl.rc('axes', grid=False) obj.plot(kind=kind, grid=True, **kws) assert is_grid_on()
Example 17
Project: info-flow-experiments Author: tadatitam File: plot.py License: GNU General Public License v3.0 | 5 votes |
def treatment_feature_histogram(X,y,feat, names): obs = np.array([[0.]*len(X[0])]*2) for i in range(0, len(y)): obs[y[i]] += X[i] colors = ['b', 'r', 'g', 'm', 'k'] # Can plot upto 5 different colors pos = np.arange(1, len(obs[0])+1) width = 0.1 # gives histogram aspect to the bar diagram gridLineWidth=0.1 fig, ax = plt.subplots() # ax.xaxis.grid(True, zorder=0) # ax.yaxis.grid(True, zorder=0) matplotlib.rc('xtick', labelsize=1) # matplotlib.gca().tight_layout() for i in range(0, len(obs)): # lbl = "treatment "+str(i) plt.bar(pos+i*width, obs[i], width, color=colors[i], alpha=0.5, label=names[i]) # plt.bar(pos, obs[0], width, color=colors[0], alpha=0.5) plt.xticks(pos+width, feat.data, rotation="vertical") # useful only for categories #plt.axis([-1, len(obs[2]), 0, len(ran1)/2+10]) plt.ylabel("# agents") feat.display() print obs[0] plt.legend() # saving: (matplotlib.pyplot).tight_layout() fig.savefig("./plots/"+"+".join(names)+".eps") # plt.show()
Example 18
Project: easyplot Author: HamsterHuey File: easyplot.py License: MIT License | 5 votes |
def set_fontsize(self, font_size): """ Updates global font size for all plot elements""" mpl.rcParams['font.size'] = font_size self.redraw() #TODO: Implement individual font size setting # params = {'font.family': 'serif', # 'font.size': 16, # 'axes.labelsize': 18, # 'text.fontsize': 18, # 'legend.fontsize': 18, # 'xtick.labelsize': 18, # 'ytick.labelsize': 18, # 'text.usetex': True} # mpl.rcParams.update(params) # def set_font(self, family=None, weight=None, size=None): # """ Updates global font properties for all plot elements # # TODO: Font family and weight don't update dynamically""" # if family is None: # family = mpl.rcParams['font.family'] # if weight is None: # weight = mpl.rcParams['font.weight'] # if size is None: # size = mpl.rcParams['font.size'] # mpl.rc('font', family=family, weight=weight, size=size) # self.redraw()
Example 19
Project: vnpy_crypto Author: birforce File: common.py License: MIT License | 5 votes |
def _check_grid_settings(self, obj, kinds, kws={}): # Make sure plot defaults to rcParams['axes.grid'] setting, GH 9792 import matplotlib as mpl def is_grid_on(): xoff = all(not g.gridOn for g in self.plt.gca().xaxis.get_major_ticks()) yoff = all(not g.gridOn for g in self.plt.gca().yaxis.get_major_ticks()) return not (xoff and yoff) spndx = 1 for kind in kinds: if not _ok_for_gaussian_kde(kind): continue self.plt.subplot(1, 4 * len(kinds), spndx) spndx += 1 mpl.rc('axes', grid=False) obj.plot(kind=kind, **kws) assert not is_grid_on() self.plt.subplot(1, 4 * len(kinds), spndx) spndx += 1 mpl.rc('axes', grid=True) obj.plot(kind=kind, grid=False, **kws) assert not is_grid_on() if kind != 'pie': self.plt.subplot(1, 4 * len(kinds), spndx) spndx += 1 mpl.rc('axes', grid=True) obj.plot(kind=kind, **kws) assert is_grid_on() self.plt.subplot(1, 4 * len(kinds), spndx) spndx += 1 mpl.rc('axes', grid=False) obj.plot(kind=kind, grid=True, **kws) assert is_grid_on()
Example 20
Project: WxConn Author: newbietian File: main.py License: MIT License | 5 votes |
def _init_plt(self): font = {'family': ['xkcd', 'Humor Sans', 'Comic Sans MS'], 'weight': 'bold', 'size': 14} matplotlib.rc('font', **font) # 这行代码使用「手绘风格图片」,有兴趣小伙伴可以google搜索「xkcd」,有好玩的。 plt.xkcd() self.bar_color = ('#55A868', '#4C72B0', '#C44E52', '#8172B2', '#CCB974', '#64B5CD') self.title_font_size = 'x-large'
Example 21
Project: WxConn Author: newbietian File: main.py License: MIT License | 5 votes |
def generate_city_pic(self, city_data): """ 生成城市数据图片 因为plt在子线程中执行会出现自动弹出弹框并阻塞主线程的行为,plt行为均放在主线程中 :param data: :return: """ font = {'family': ['xkcd', 'Humor Sans', 'Comic Sans MS'], 'weight': 'bold', 'size': 12} matplotlib.rc('font', **font) cities = city_data['cities'] city_people = city_data['city_people'] # 绘制「性别分布」柱状图 plt.barh(range(len(cities)), width=city_people, align='center', color=self.bar_color, alpha=0.8) # 添加轴标签 plt.xlabel(u'Number of People') # 添加标题 plt.title(u'Top %d Cities of your friends distributed' % len(cities), fontsize=self.title_font_size) # 添加刻度标签 plt.yticks(range(len(cities)), cities) # 设置X轴的刻度范围 plt.xlim([0, city_people[0] * 1.1]) # 为每个条形图添加数值标签 for x, y in enumerate(city_people): plt.text(y + len(str(y)), x, y, ha='center') # 显示图形 plt.savefig(ALS.result_path + '/4.png') # todo 如果调用此处的关闭,就会导致应用本身也被关闭 # plt.close() # plt.show()
Example 22
Project: Computable Author: ktraunmueller File: pyplot.py License: MIT License | 5 votes |
def rc(*args, **kwargs): matplotlib.rc(*args, **kwargs)
Example 23
Project: Computable Author: ktraunmueller File: pyplot.py License: MIT License | 5 votes |
def rc_context(rc=None, fname=None): return matplotlib.rc_context(rc, fname)
Example 24
Project: Computable Author: ktraunmueller File: pyplot.py License: MIT License | 5 votes |
def hold(b=None): """ Set the hold state. If *b* is None (default), toggle the hold state, else set the hold state to boolean value *b*:: hold() # toggle hold hold(True) # hold is on hold(False) # hold is off When *hold* is *True*, subsequent plot commands will be added to the current axes. When *hold* is *False*, the current axes and figure will be cleared on the next plot command. """ fig = gcf() ax = fig.gca() fig.hold(b) ax.hold(b) # b=None toggles the hold state, so let's get get the current hold # state; but should pyplot hold toggle the rc setting - me thinks # not b = ax.ishold() rc('axes', hold=b)
Example 25
Project: Computable Author: ktraunmueller File: pyplot.py License: MIT License | 5 votes |
def bone(): ''' set the default colormap to bone and apply to current image if any. See help(colormaps) for more information ''' rc('image', cmap='bone') im = gci() if im is not None: im.set_cmap(cm.bone) draw_if_interactive() # This function was autogenerated by boilerplate.py. Do not edit as # changes will be lost
Example 26
Project: Computable Author: ktraunmueller File: pyplot.py License: MIT License | 5 votes |
def cool(): ''' set the default colormap to cool and apply to current image if any. See help(colormaps) for more information ''' rc('image', cmap='cool') im = gci() if im is not None: im.set_cmap(cm.cool) draw_if_interactive() # This function was autogenerated by boilerplate.py. Do not edit as # changes will be lost
Example 27
Project: Computable Author: ktraunmueller File: pyplot.py License: MIT License | 5 votes |
def copper(): ''' set the default colormap to copper and apply to current image if any. See help(colormaps) for more information ''' rc('image', cmap='copper') im = gci() if im is not None: im.set_cmap(cm.copper) draw_if_interactive() # This function was autogenerated by boilerplate.py. Do not edit as # changes will be lost
Example 28
Project: Computable Author: ktraunmueller File: pyplot.py License: MIT License | 5 votes |
def flag(): ''' set the default colormap to flag and apply to current image if any. See help(colormaps) for more information ''' rc('image', cmap='flag') im = gci() if im is not None: im.set_cmap(cm.flag) draw_if_interactive() # This function was autogenerated by boilerplate.py. Do not edit as # changes will be lost
Example 29
Project: Computable Author: ktraunmueller File: pyplot.py License: MIT License | 5 votes |
def gray(): ''' set the default colormap to gray and apply to current image if any. See help(colormaps) for more information ''' rc('image', cmap='gray') im = gci() if im is not None: im.set_cmap(cm.gray) draw_if_interactive() # This function was autogenerated by boilerplate.py. Do not edit as # changes will be lost
Example 30
Project: Computable Author: ktraunmueller File: pyplot.py License: MIT License | 5 votes |
def hsv(): ''' set the default colormap to hsv and apply to current image if any. See help(colormaps) for more information ''' rc('image', cmap='hsv') im = gci() if im is not None: im.set_cmap(cm.hsv) draw_if_interactive() # This function was autogenerated by boilerplate.py. Do not edit as # changes will be lost