Python matplotlib.pylab.bar() Examples
The following are 10
code examples of matplotlib.pylab.bar().
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 also want to check out all available functions/classes of the module
matplotlib.pylab
, or try the search function
.
Example #1
Source File: utils.py From Building-Machine-Learning-Systems-With-Python-Second-Edition with MIT License | 6 votes |
def plot_feat_importance(feature_names, clf, name): pylab.clf() coef_ = clf.coef_ important = np.argsort(np.absolute(coef_.ravel())) f_imp = feature_names[important] coef = coef_.ravel()[important] inds = np.argsort(coef) f_imp = f_imp[inds] coef = coef[inds] xpos = np.array(range(len(coef))) pylab.bar(xpos, coef, width=1) pylab.title('Feature importance for %s' % (name)) ax = pylab.gca() ax.set_xticks(np.arange(len(coef))) labels = ax.set_xticklabels(f_imp) for label in labels: label.set_rotation(90) filename = name.replace(" ", "_") pylab.savefig(os.path.join( CHART_DIR, "feat_imp_%s.png" % filename), bbox_inches="tight")
Example #2
Source File: utils.py From Building-Machine-Learning-Systems-With-Python-Second-Edition with MIT License | 6 votes |
def plot_feat_importance(feature_names, clf, name): pylab.clf() coef_ = clf.coef_ important = np.argsort(np.absolute(coef_.ravel())) f_imp = feature_names[important] coef = coef_.ravel()[important] inds = np.argsort(coef) f_imp = f_imp[inds] coef = coef[inds] xpos = np.array(range(len(coef))) pylab.bar(xpos, coef, width=1) pylab.title('Feature importance for %s' % (name)) ax = pylab.gca() ax.set_xticks(np.arange(len(coef))) labels = ax.set_xticklabels(f_imp) for label in labels: label.set_rotation(90) filename = name.replace(" ", "_") pylab.savefig(os.path.join( CHART_DIR, "feat_imp_%s.png" % filename), bbox_inches="tight")
Example #3
Source File: utils.py From Building-Machine-Learning-Systems-With-Python-Second-Edition with MIT License | 6 votes |
def plot_feat_importance(feature_names, clf, name): pylab.figure(num=None, figsize=(6, 5)) coef_ = clf.coef_ important = np.argsort(np.absolute(coef_.ravel())) f_imp = feature_names[important] coef = coef_.ravel()[important] inds = np.argsort(coef) f_imp = f_imp[inds] coef = coef[inds] xpos = np.array(list(range(len(coef)))) pylab.bar(xpos, coef, width=1) pylab.title('Feature importance for %s' % (name)) ax = pylab.gca() ax.set_xticks(np.arange(len(coef))) labels = ax.set_xticklabels(f_imp) for label in labels: label.set_rotation(90) filename = name.replace(" ", "_") pylab.savefig(os.path.join( CHART_DIR, "feat_imp_%s.png" % filename), bbox_inches="tight")
Example #4
Source File: base.py From pylift with BSD 2-Clause "Simplified" License | 6 votes |
def _plot_NWOE_bins(NWOE_dict, feats): """ Plots the NWOE by bin for the subset of features interested in (form of list) Parameters ---------- - NWOE_dict = dictionary output of `NWOE` function - feats = list of features to plot NWOE for Returns ------- - plots of NWOE for each feature by bin """ for feat in feats: fig, ax = _plot_defaults() feat_df = NWOE_dict[feat].reset_index() plt.bar(range(len(feat_df)), feat_df['NWOE'], tick_label=feat_df[str(feat)+'_bin'], color='k', alpha=0.5) plt.xticks(rotation='vertical') ax.set_title('NWOE by bin for '+str(feat)) ax.set_xlabel('Bin Interval'); return ax
Example #5
Source File: base.py From pylift with BSD 2-Clause "Simplified" License | 6 votes |
def _plot_NWOE_bins(NWOE_dict, feats): """ Plots the NWOE by bin for the subset of features interested in (form of list) Parameters ---------- - NWOE_dict = dictionary output of `NWOE` function - feats = list of features to plot NWOE for Returns ------- - plots of NWOE for each feature by bin """ for feat in feats: fig, ax = _plot_defaults() feat_df = NWOE_dict[feat].reset_index() plt.bar(range(len(feat_df)), feat_df['NWOE'], tick_label=feat_df[str(feat)+'_bin'], color='k', alpha=0.5) plt.xticks(rotation='vertical') ax.set_title('NWOE by bin for '+str(feat)) ax.set_xlabel('Bin Interval'); return ax
Example #6
Source File: 07_dqn_distrib.py From Deep-Reinforcement-Learning-Hands-On with MIT License | 6 votes |
def save_state_images(frame_idx, states, net, device="cpu", max_states=200): ofs = 0 p = np.arange(Vmin, Vmax + DELTA_Z, DELTA_Z) for batch in np.array_split(states, 64): states_v = torch.tensor(batch).to(device) action_prob = net.apply_softmax(net(states_v)).data.cpu().numpy() batch_size, num_actions, _ = action_prob.shape for batch_idx in range(batch_size): plt.clf() for action_idx in range(num_actions): plt.subplot(num_actions, 1, action_idx+1) plt.bar(p, action_prob[batch_idx, action_idx], width=0.5) plt.savefig("states/%05d_%08d.png" % (ofs + batch_idx, frame_idx)) ofs += batch_size if ofs >= max_states: break
Example #7
Source File: 07_dqn_distrib.py From Deep-Reinforcement-Learning-Hands-On with MIT License | 6 votes |
def save_transition_images(batch_size, predicted, projected, next_distr, dones, rewards, save_prefix): for batch_idx in range(batch_size): is_done = dones[batch_idx] reward = rewards[batch_idx] plt.clf() p = np.arange(Vmin, Vmax + DELTA_Z, DELTA_Z) plt.subplot(3, 1, 1) plt.bar(p, predicted[batch_idx], width=0.5) plt.title("Predicted") plt.subplot(3, 1, 2) plt.bar(p, projected[batch_idx], width=0.5) plt.title("Projected") plt.subplot(3, 1, 3) plt.bar(p, next_distr[batch_idx], width=0.5) plt.title("Next state") suffix = "" if reward != 0.0: suffix = suffix + "_%.0f" % reward if is_done: suffix = suffix + "_done" plt.savefig("%s_%02d%s.png" % (save_prefix, batch_idx, suffix))
Example #8
Source File: util.py From Azimuth with BSD 3-Clause "New" or "Revised" License | 5 votes |
def autolabel(ax, rects, strfrm='%.2f'): ''' Automatically add value over each bar in bar chart http://matplotlib.org/1.4.2/examples/api/barchart_demo.html ''' for rect in rects: height = rect.get_height() ax.text(rect.get_x()+rect.get_width()/2., 1.05*height, strfrm % float(height), ha='center', va='bottom')
Example #9
Source File: PlotComps.py From refinery with MIT License | 5 votes |
def plotData(Data, nObsPlot=5000): ''' Plot data items, at most nObsPlot distinct points (for quick rendering) ''' if type(Data) == bnpy.data.XData: PRNG = np.random.RandomState(nObsPlot) pIDs = PRNG.permutation(Data.nObs)[:nObsPlot] if Data.dim > 1: pylab.plot(Data.X[pIDs,0], Data.X[pIDs,1], 'k.') else: hist, bin_edges = pylab.histogram(Data.X, bins=25) xs = bin_edges[:-1] ys = np.asarray(hist, dtype=np.float32) / np.sum(hist) pylab.bar(xs, ys, width=0.8*(bin_edges[1]-bin_edges[0]), color='k')
Example #10
Source File: run.py From ipython-cypher with GNU General Public License v2.0 | 5 votes |
def bar(self, key_word_sep=" ", title=None, **kwargs): """Generates a pylab bar plot from the result set. ``matplotlib`` must be installed, and in an IPython Notebook, inlining must be on:: %%matplotlib inline The last quantitative column is taken as the Y values; all other columns are combined to label the X axis. :param title: plot title, defaults to names of Y value columns :param key_word_sep: string used to separate column values from each other in labels Any additional keyword arguments will be passsed through to ``matplotlib.pylab.bar``. """ if not plt: raise ImportError("Try installing matplotlib first.") self.guess_pie_columns(xlabel_sep=key_word_sep) plot = plt.bar(range(len(self.ys[0])), self.ys[0], **kwargs) if self.xlabels: plt.xticks(range(len(self.xlabels)), self.xlabels, rotation=45) plt.xlabel(self.xlabel) plt.ylabel(self.ys[0].name) return plot