From 218e358168fe898267c9a43bebec60ca183e68b3 Mon Sep 17 00:00:00 2001 From: David Stansby Date: Sat, 24 Jun 2017 14:49:19 +0100 Subject: [PATCH 1/4] Move and clean some pylab examples Restore changes to moved files --- .../arctest.py | 6 +- .../bar_stacked.py | 2 +- examples/pylab_examples/axhspan_demo.py | 39 -------- .../anscombe.py | 8 +- .../axes_demo.py | 8 +- .../axes_props.py | 0 .../axes_zoom_effect.py | 2 +- examples/subplots_axes_and_figures/axhspan_demo.py | 39 ++++++++ .../axis_equal_demo.py | 10 +- .../broken_axis.py | 0 .../figure_title.py | 0 .../invert_axes.py | 0 .../arrow_demo.py | 101 +++++++++++---------- .../arrow_simple_demo.py | 0 .../fancyarrow_demo.py | 9 +- .../centered_ticklabels.py | 2 +- .../colorbar_tick_labelling_demo.py | 0 17 files changed, 115 insertions(+), 111 deletions(-) rename examples/{pylab_examples => lines_bars_and_markers}/arctest.py (80%) rename examples/{pylab_examples => lines_bars_and_markers}/bar_stacked.py (93%) delete mode 100644 examples/pylab_examples/axhspan_demo.py rename examples/{pylab_examples => specialty_plots}/anscombe.py (91%) rename examples/{pylab_examples => subplots_axes_and_figures}/axes_demo.py (80%) rename examples/{pylab_examples => subplots_axes_and_figures}/axes_props.py (100%) rename examples/{pylab_examples => subplots_axes_and_figures}/axes_zoom_effect.py (98%) create mode 100644 examples/subplots_axes_and_figures/axhspan_demo.py rename examples/{pylab_examples => subplots_axes_and_figures}/axis_equal_demo.py (74%) rename examples/{pylab_examples => subplots_axes_and_figures}/broken_axis.py (100%) rename examples/{pylab_examples => subplots_axes_and_figures}/figure_title.py (100%) rename examples/{pylab_examples => subplots_axes_and_figures}/invert_axes.py (100%) rename examples/{pylab_examples => text_labels_and_annotations}/arrow_demo.py (77%) rename examples/{pylab_examples => text_labels_and_annotations}/arrow_simple_demo.py (100%) rename examples/{pylab_examples => text_labels_and_annotations}/fancyarrow_demo.py (87%) rename examples/{pylab_examples => ticks_and_spines}/centered_ticklabels.py (98%) rename examples/{pylab_examples => ticks_and_spines}/colorbar_tick_labelling_demo.py (100%) diff --git a/examples/pylab_examples/arctest.py b/examples/lines_bars_and_markers/arctest.py similarity index 80% rename from examples/pylab_examples/arctest.py rename to examples/lines_bars_and_markers/arctest.py index f240407d537..5f42e27e70c 100644 --- a/examples/pylab_examples/arctest.py +++ b/examples/lines_bars_and_markers/arctest.py @@ -9,16 +9,16 @@ def f(t): - 'a damped exponential' + 'A damped exponential' s1 = np.cos(2 * np.pi * t) e1 = np.exp(-t) return s1 * e1 -t1 = np.arange(0.0, 5.0, .2) +t1 = np.arange(0.0, 5.0, .2) l = plt.plot(t1, f(t1), 'ro') plt.setp(l, 'markersize', 30) -plt.setp(l, 'markerfacecolor', 'b') +plt.setp(l, 'markerfacecolor', 'C0') plt.show() diff --git a/examples/pylab_examples/bar_stacked.py b/examples/lines_bars_and_markers/bar_stacked.py similarity index 93% rename from examples/pylab_examples/bar_stacked.py rename to examples/lines_bars_and_markers/bar_stacked.py index d7fb25b080c..d5bb2eca958 100644 --- a/examples/pylab_examples/bar_stacked.py +++ b/examples/lines_bars_and_markers/bar_stacked.py @@ -22,7 +22,7 @@ ind = np.arange(N) # the x locations for the groups width = 0.35 # the width of the bars: can also be len(x) sequence -p1 = plt.bar(ind, menMeans, width, color='#d62728', yerr=menStd) +p1 = plt.bar(ind, menMeans, width, yerr=menStd) p2 = plt.bar(ind, womenMeans, width, bottom=menMeans, yerr=womenStd) diff --git a/examples/pylab_examples/axhspan_demo.py b/examples/pylab_examples/axhspan_demo.py deleted file mode 100644 index 8e9eac28ce6..00000000000 --- a/examples/pylab_examples/axhspan_demo.py +++ /dev/null @@ -1,39 +0,0 @@ -""" -============ -Axhspan Demo -============ - -Create lines or rectangles that span the axes in either the horizontal or vertical direction. -""" -import numpy as np -import matplotlib.pyplot as plt - -t = np.arange(-1, 2, .01) -s = np.sin(2*np.pi*t) - -plt.plot(t, s) -# draw a thick red hline at y=0 that spans the xrange -l = plt.axhline(linewidth=8, color='#d62728') - -# draw a default hline at y=1 that spans the xrange -l = plt.axhline(y=1) - -# draw a default vline at x=1 that spans the yrange -l = plt.axvline(x=1) - -# draw a thick blue vline at x=0 that spans the upper quadrant of -# the yrange -l = plt.axvline(x=0, ymin=0.75, linewidth=8, color='#1f77b4') - -# draw a default hline at y=.5 that spans the middle half of -# the axes -l = plt.axhline(y=.5, xmin=0.25, xmax=0.75) - -p = plt.axhspan(0.25, 0.75, facecolor='0.5', alpha=0.5) - -p = plt.axvspan(1.25, 1.55, facecolor='#2ca02c', alpha=0.5) - -plt.axis([-1, 2, -1, 2]) - - -plt.show() diff --git a/examples/pylab_examples/anscombe.py b/examples/specialty_plots/anscombe.py similarity index 91% rename from examples/pylab_examples/anscombe.py rename to examples/specialty_plots/anscombe.py index 2b8f633175b..fd1ecd0bbe5 100644 --- a/examples/pylab_examples/anscombe.py +++ b/examples/specialty_plots/anscombe.py @@ -25,7 +25,7 @@ def fit(x): - return 3 + 0.5*x + return 3 + 0.5 * x xfit = np.array([np.min(x), np.max(x)]) @@ -39,7 +39,8 @@ def fit(x): plt.subplot(222) plt.plot(x, y2, 'ks', xfit, fit(xfit), 'r-', lw=2) plt.axis([2, 20, 2, 14]) -plt.setp(plt.gca(), xticklabels=[], yticks=(4, 8, 12), yticklabels=[], xticks=(0, 10, 20)) +plt.setp(plt.gca(), xticks=(0, 10, 20), xticklabels=[], + yticks=(4, 8, 12), yticklabels=[], ) plt.text(3, 12, 'II', fontsize=20) plt.subplot(223) @@ -58,6 +59,7 @@ def fit(x): # verify the stats pairs = (x, y1), (x, y2), (x, y3), (x4, y4) for x, y in pairs: - print('mean=%1.2f, std=%1.2f, r=%1.2f' % (np.mean(y), np.std(y), np.corrcoef(x, y)[0][1])) + print('mean=%1.2f, std=%1.2f, r=%1.2f' % (np.mean(y), np.std(y), + np.corrcoef(x, y)[0][1])) plt.show() diff --git a/examples/pylab_examples/axes_demo.py b/examples/subplots_axes_and_figures/axes_demo.py similarity index 80% rename from examples/pylab_examples/axes_demo.py rename to examples/subplots_axes_and_figures/axes_demo.py index 36b23d2c7b3..ee6bb512931 100644 --- a/examples/pylab_examples/axes_demo.py +++ b/examples/subplots_axes_and_figures/axes_demo.py @@ -15,9 +15,9 @@ # create some data to use for the plot dt = 0.001 t = np.arange(0.0, 10.0, dt) -r = np.exp(-t[:1000]/0.05) # impulse response +r = np.exp(-t[:1000] / 0.05) # impulse response x = np.random.randn(len(t)) -s = np.convolve(x, r)[:len(x)]*dt # colored noise +s = np.convolve(x, r)[:len(x)] * dt # colored noise # the main axes is subplot(111) by default plt.plot(t, s) @@ -27,14 +27,14 @@ plt.title('Gaussian colored noise') # this is an inset axes over the main axes -a = plt.axes([.65, .6, .2, .2], facecolor='y') +a = plt.axes([.65, .6, .2, .2], facecolor='k') n, bins, patches = plt.hist(s, 400, normed=1) plt.title('Probability') plt.xticks([]) plt.yticks([]) # this is another inset axes over the main axes -a = plt.axes([0.2, 0.6, .2, .2], facecolor='y') +a = plt.axes([0.2, 0.6, .2, .2], facecolor='k') plt.plot(t[:len(r)], r) plt.title('Impulse response') plt.xlim(0, 0.2) diff --git a/examples/pylab_examples/axes_props.py b/examples/subplots_axes_and_figures/axes_props.py similarity index 100% rename from examples/pylab_examples/axes_props.py rename to examples/subplots_axes_and_figures/axes_props.py diff --git a/examples/pylab_examples/axes_zoom_effect.py b/examples/subplots_axes_and_figures/axes_zoom_effect.py similarity index 98% rename from examples/pylab_examples/axes_zoom_effect.py rename to examples/subplots_axes_and_figures/axes_zoom_effect.py index cea32220601..0cae0a04a5d 100644 --- a/examples/pylab_examples/axes_zoom_effect.py +++ b/examples/subplots_axes_and_figures/axes_zoom_effect.py @@ -16,7 +16,7 @@ def connect_bbox(bbox1, bbox2, prop_lines, prop_patches=None): if prop_patches is None: prop_patches = prop_lines.copy() - prop_patches["alpha"] = prop_patches.get("alpha", 1)*0.2 + prop_patches["alpha"] = prop_patches.get("alpha", 1) * 0.2 c1 = BboxConnector(bbox1, bbox2, loc1=loc1a, loc2=loc2a, **prop_lines) c1.set_clip_on(False) diff --git a/examples/subplots_axes_and_figures/axhspan_demo.py b/examples/subplots_axes_and_figures/axhspan_demo.py new file mode 100644 index 00000000000..ddf1a3706e9 --- /dev/null +++ b/examples/subplots_axes_and_figures/axhspan_demo.py @@ -0,0 +1,39 @@ +""" +============ +Axhspan Demo +============ + +Create lines or rectangles that span the axes in either the horizontal or +vertical direction. +""" +import numpy as np +import matplotlib.pyplot as plt + +t = np.arange(-1, 2, .01) +s = np.sin(2 * np.pi * t) + +plt.plot(t, s) +# Draw a thick red hline at y=0 that spans the xrange +plt.axhline(linewidth=8, color='#d62728') + +# Draw a default hline at y=1 that spans the xrange +plt.axhline(y=1) + +# Draw a default vline at x=1 that spans the yrange +plt.axvline(x=1) + +# Draw a thick blue vline at x=0 that spans the upper quadrant of +# the yrange +plt.axvline(x=0, ymin=0.75, linewidth=8, color='#1f77b4') + +# Draw a default hline at y=.5 that spans the middle half of +# the axes +plt.axhline(y=.5, xmin=0.25, xmax=0.75) + +plt.axhspan(0.25, 0.75, facecolor='0.5', alpha=0.5) + +plt.axvspan(1.25, 1.55, facecolor='#2ca02c', alpha=0.5) + +plt.axis([-1, 2, -1, 2]) + +plt.show() diff --git a/examples/pylab_examples/axis_equal_demo.py b/examples/subplots_axes_and_figures/axis_equal_demo.py similarity index 74% rename from examples/pylab_examples/axis_equal_demo.py rename to examples/subplots_axes_and_figures/axis_equal_demo.py index 568b89966cd..20af5c9f4dc 100644 --- a/examples/pylab_examples/axis_equal_demo.py +++ b/examples/subplots_axes_and_figures/axis_equal_demo.py @@ -11,22 +11,22 @@ # Plot circle of radius 3. -an = np.linspace(0, 2*np.pi, 100) +an = np.linspace(0, 2 * np.pi, 100) fig, axs = plt.subplots(2, 2) -axs[0, 0].plot(3*np.cos(an), 3*np.sin(an)) +axs[0, 0].plot(3 * np.cos(an), 3 * np.sin(an)) axs[0, 0].set_title('not equal, looks like ellipse', fontsize=10) -axs[0, 1].plot(3*np.cos(an), 3*np.sin(an)) +axs[0, 1].plot(3 * np.cos(an), 3 * np.sin(an)) axs[0, 1].axis('equal') axs[0, 1].set_title('equal, looks like circle', fontsize=10) -axs[1, 0].plot(3*np.cos(an), 3*np.sin(an)) +axs[1, 0].plot(3 * np.cos(an), 3 * np.sin(an)) axs[1, 0].axis('equal') axs[1, 0].axis([-3, 3, -3, 3]) axs[1, 0].set_title('still a circle, even after changing limits', fontsize=10) -axs[1, 1].plot(3*np.cos(an), 3*np.sin(an)) +axs[1, 1].plot(3 * np.cos(an), 3 * np.sin(an)) axs[1, 1].set_aspect('equal', 'box') axs[1, 1].set_title('still a circle, auto-adjusted data limits', fontsize=10) diff --git a/examples/pylab_examples/broken_axis.py b/examples/subplots_axes_and_figures/broken_axis.py similarity index 100% rename from examples/pylab_examples/broken_axis.py rename to examples/subplots_axes_and_figures/broken_axis.py diff --git a/examples/pylab_examples/figure_title.py b/examples/subplots_axes_and_figures/figure_title.py similarity index 100% rename from examples/pylab_examples/figure_title.py rename to examples/subplots_axes_and_figures/figure_title.py diff --git a/examples/pylab_examples/invert_axes.py b/examples/subplots_axes_and_figures/invert_axes.py similarity index 100% rename from examples/pylab_examples/invert_axes.py rename to examples/subplots_axes_and_figures/invert_axes.py diff --git a/examples/pylab_examples/arrow_demo.py b/examples/text_labels_and_annotations/arrow_demo.py similarity index 77% rename from examples/pylab_examples/arrow_demo.py rename to examples/text_labels_and_annotations/arrow_demo.py index 22b49cc9db9..00d4a57f6fc 100644 --- a/examples/pylab_examples/arrow_demo.py +++ b/examples/text_labels_and_annotations/arrow_demo.py @@ -33,7 +33,8 @@ def add_dicts(d1, d2): def make_arrow_plot(data, size=4, display='length', shape='right', max_arrow_width=0.03, arrow_sep=0.02, alpha=0.5, normalize_data=False, ec=None, labelcolor=None, - head_starts_at_zero=True, rate_labels=lettered_bases_to_rates, + head_starts_at_zero=True, + rate_labels=lettered_bases_to_rates, **kwargs): """Makes an arrow plot. @@ -56,9 +57,9 @@ def make_arrow_plot(data, size=4, display='length', shape='right', plt.gcf().set_size_inches(size, size) plt.xticks([]) plt.yticks([]) - max_text_size = size*12 + max_text_size = size * 12 min_text_size = size - label_text_size = size*2.5 + label_text_size = size * 2.5 text_params = {'ha': 'center', 'va': 'center', 'family': 'sans-serif', 'fontweight': 'bold'} r2 = np.sqrt(2) @@ -68,15 +69,14 @@ def make_arrow_plot(data, size=4, display='length', shape='right', 'TA': (-1, 0), 'GA': (0, 1), 'AG': (0, -1), - 'CA': (-1/r2, 1/r2), - 'AC': (1/r2, -1/r2), - 'GT': (1/r2, 1/r2), - 'TG': (-1/r2, -1/r2), + 'CA': (-1 / r2, 1 / r2), + 'AC': (1 / r2, -1 / r2), + 'GT': (1 / r2, 1 / r2), + 'TG': (-1 / r2, -1 / r2), 'CT': (0, 1), 'TC': (0, -1), 'GC': (1, 0), - 'CG': (-1, 0) - } + 'CG': (-1, 0)} colors = { 'AT': 'r', @@ -90,8 +90,7 @@ def make_arrow_plot(data, size=4, display='length', shape='right', 'CT': 'b', 'TC': 'k', 'GC': 'g', - 'CG': 'b' - } + 'CG': 'b'} label_positions = { 'AT': 'center', @@ -105,29 +104,32 @@ def make_arrow_plot(data, size=4, display='length', shape='right', 'CT': 'center', 'TC': 'center', 'GC': 'center', - 'CG': 'center' - } + 'CG': 'center'} def do_fontsize(k): - return float(np.clip(max_text_size*np.sqrt(data[k]), - min_text_size, max_text_size)) - - A = plt.text(0, 1, '$A_3$', color='r', size=do_fontsize('A'), **text_params) - T = plt.text(1, 1, '$T_3$', color='k', size=do_fontsize('T'), **text_params) - G = plt.text(0, 0, '$G_3$', color='g', size=do_fontsize('G'), **text_params) - C = plt.text(1, 0, '$C_3$', color='b', size=do_fontsize('C'), **text_params) + return float(np.clip(max_text_size * np.sqrt(data[k]), + min_text_size, max_text_size)) + + A = plt.text(0, 1, '$A_3$', color='r', size=do_fontsize('A'), + **text_params) + T = plt.text(1, 1, '$T_3$', color='k', size=do_fontsize('T'), + **text_params) + G = plt.text(0, 0, '$G_3$', color='g', size=do_fontsize('G'), + **text_params) + C = plt.text(1, 0, '$C_3$', color='b', size=do_fontsize('C'), + **text_params) arrow_h_offset = 0.25 # data coordinates, empirically determined - max_arrow_length = 1 - 2*arrow_h_offset - max_head_width = 2.5*max_arrow_width - max_head_length = 2*max_arrow_width + max_arrow_length = 1 - 2 * arrow_h_offset + max_head_width = 2.5 * max_arrow_width + max_head_length = 2 * max_arrow_width arrow_params = {'length_includes_head': True, 'shape': shape, 'head_starts_at_zero': head_starts_at_zero} ax = plt.gca() sf = 0.6 # max arrow size represents this in data coords - d = (r2/2 + arrow_h_offset - 0.5)/r2 # distance for diags - r2v = arrow_sep/r2 # offset for diags + d = (r2 / 2 + arrow_h_offset - 0.5) / r2 # distance for diags + r2v = arrow_sep / r2 # offset for diags # tuple of x, y for start position positions = { @@ -142,8 +144,7 @@ def do_fontsize(k): 'CT': (1 - arrow_sep, arrow_h_offset), 'TC': (1 + arrow_sep, 1 - arrow_h_offset), 'GC': (arrow_h_offset, arrow_sep), - 'CG': (1 - arrow_h_offset, -arrow_sep), - } + 'CG': (1 - arrow_h_offset, -arrow_sep)} if normalize_data: # find maximum value for rates, i.e. where keys are 2 chars long @@ -153,25 +154,25 @@ def do_fontsize(k): max_val = max(max_val, v) # divide rates by max val, multiply by arrow scale factor for k, v in data.items(): - data[k] = v/max_val*sf + data[k] = v / max_val * sf def draw_arrow(pair, alpha=alpha, ec=ec, labelcolor=labelcolor): # set the length of the arrow if display == 'length': - length = max_head_length + data[pair]/sf*(max_arrow_length - - max_head_length) + length = max_head_length + data[pair] / sf * (max_arrow_length - + max_head_length) else: length = max_arrow_length # set the transparency of the arrow if display == 'alpha': - alpha = min(data[pair]/sf, alpha) + alpha = min(data[pair] / sf, alpha) # set the width of the arrow if display == 'width': - scale = data[pair]/sf - width = max_arrow_width*scale - head_width = max_head_width*scale - head_length = max_head_length*scale + scale = data[pair] / sf + width = max_arrow_width * scale + head_width = max_head_width * scale + head_length = max_head_length * scale else: width = max_arrow_width head_width = max_head_width @@ -182,9 +183,10 @@ def draw_arrow(pair, alpha=alpha, ec=ec, labelcolor=labelcolor): x_scale, y_scale = deltas[pair] x_pos, y_pos = positions[pair] - plt.arrow(x_pos, y_pos, x_scale*length, y_scale*length, - fc=fc, ec=ec, alpha=alpha, width=width, head_width=head_width, - head_length=head_length, **arrow_params) + plt.arrow(x_pos, y_pos, x_scale * length, y_scale * length, + fc=fc, ec=ec, alpha=alpha, width=width, + head_width=head_width, head_length=head_length, + **arrow_params) # figure out coordinates for text # if drawing relative to base: x and y are same as for arrow @@ -195,14 +197,15 @@ def draw_arrow(pair, alpha=alpha, ec=ec, labelcolor=labelcolor): where = label_positions[pair] if where == 'left': - orig_position = 3*np.array([[max_arrow_width, max_arrow_width]]) + orig_position = 3 * np.array([[max_arrow_width, max_arrow_width]]) elif where == 'absolute': - orig_position = np.array([[max_arrow_length/2.0, 3*max_arrow_width]]) + orig_position = np.array([[max_arrow_length / 2.0, + 3 * max_arrow_width]]) elif where == 'right': - orig_position = np.array([[length - 3*max_arrow_width, - 3*max_arrow_width]]) + orig_position = np.array([[length - 3 * max_arrow_width, + 3 * max_arrow_width]]) elif where == 'center': - orig_position = np.array([[length/2.0, 3*max_arrow_width]]) + orig_position = np.array([[length / 2.0, 3 * max_arrow_width]]) else: raise ValueError("Got unknown position parameter %s" % where) @@ -213,11 +216,12 @@ def draw_arrow(pair, alpha=alpha, ec=ec, labelcolor=labelcolor): label = '$%s_{_{\mathrm{%s}}}$' % (orig_label[0], orig_label[1:]) plt.text(x, y, label, size=label_text_size, ha='center', va='center', - color=labelcolor or fc) + color=labelcolor or fc) for p in sorted(positions): draw_arrow(p) + # test data all_on_max = dict([(i, 1) for i in 'TCAG'] + [(i + j, 0.6) for i in 'TCAG' for j in 'TCAG']) @@ -238,8 +242,7 @@ def draw_arrow(pair, alpha=alpha, ec=ec, labelcolor=labelcolor): 'CA': 0.2, 'GA': 0.1, 'GT': 0.4, - 'GC': 0.1, - } + 'GC': 0.1} extreme_data = { 'A': 0.75, @@ -257,8 +260,7 @@ def draw_arrow(pair, alpha=alpha, ec=ec, labelcolor=labelcolor): 'CA': 0.2, 'GA': 0.1, 'GT': 0.4, - 'GC': 0.2, - } + 'GC': 0.2} sample_data = { 'A': 0.2137, @@ -276,8 +278,7 @@ def draw_arrow(pair, alpha=alpha, ec=ec, labelcolor=labelcolor): 'CA': 0.0703, 'GA': 0.1824, 'GT': 0.0387, - 'GC': 0.1106, - } + 'GC': 0.1106} if __name__ == '__main__': diff --git a/examples/pylab_examples/arrow_simple_demo.py b/examples/text_labels_and_annotations/arrow_simple_demo.py similarity index 100% rename from examples/pylab_examples/arrow_simple_demo.py rename to examples/text_labels_and_annotations/arrow_simple_demo.py diff --git a/examples/pylab_examples/fancyarrow_demo.py b/examples/text_labels_and_annotations/fancyarrow_demo.py similarity index 87% rename from examples/pylab_examples/fancyarrow_demo.py rename to examples/text_labels_and_annotations/fancyarrow_demo.py index c1bed843f2b..2a35d9212ab 100644 --- a/examples/pylab_examples/fancyarrow_demo.py +++ b/examples/text_labels_and_annotations/fancyarrow_demo.py @@ -12,13 +12,13 @@ ncol = 2 nrow = (len(styles) + 1) // ncol figheight = (nrow + 0.5) -fig1 = plt.figure(1, (4.*ncol/1.5, figheight/1.5)) +fig1 = plt.figure(1, (4 * ncol / 1.5, figheight / 1.5)) fontsize = 0.2 * 70 ax = fig1.add_axes([0, 0, 1, 1], frameon=False, aspect=1.) -ax.set_xlim(0, 4*ncol) +ax.set_xlim(0, 4 * ncol) ax.set_ylim(0, figheight) @@ -28,15 +28,16 @@ def to_texstring(s): s = s.replace("|", r"$|$") return s + for i, (stylename, styleclass) in enumerate(sorted(styles.items())): - x = 3.2 + (i//nrow)*4 + x = 3.2 + (i // nrow) * 4 y = (figheight - 0.7 - i % nrow) # /figheight p = mpatches.Circle((x, y), 0.2) ax.add_patch(p) ax.annotate(to_texstring(stylename), (x, y), (x - 1.2, y), - #xycoords="figure fraction", textcoords="figure fraction", + # xycoords="figure fraction", textcoords="figure fraction", ha="right", va="center", size=fontsize, arrowprops=dict(arrowstyle=stylename, diff --git a/examples/pylab_examples/centered_ticklabels.py b/examples/ticks_and_spines/centered_ticklabels.py similarity index 98% rename from examples/pylab_examples/centered_ticklabels.py rename to examples/ticks_and_spines/centered_ticklabels.py index 11b80bd13f9..8c36fe1e147 100644 --- a/examples/pylab_examples/centered_ticklabels.py +++ b/examples/ticks_and_spines/centered_ticklabels.py @@ -45,6 +45,6 @@ tick.tick2line.set_markersize(0) tick.label1.set_horizontalalignment('center') -imid = len(r)//2 +imid = len(r) // 2 ax.set_xlabel(str(date[imid].year)) plt.show() diff --git a/examples/pylab_examples/colorbar_tick_labelling_demo.py b/examples/ticks_and_spines/colorbar_tick_labelling_demo.py similarity index 100% rename from examples/pylab_examples/colorbar_tick_labelling_demo.py rename to examples/ticks_and_spines/colorbar_tick_labelling_demo.py From b045455b798348195c787138b934bb11701d9716 Mon Sep 17 00:00:00 2001 From: David Stansby Date: Thu, 29 Jun 2017 18:09:42 +0100 Subject: [PATCH 2/4] Update doc references --- doc/faq/howto_faq.rst | 5 ++--- examples/recipes/fill_between_alpha.py | 2 +- tutorials/01_introductory/pyplot.py | 2 +- tutorials/text/annotations.py | 8 ++++---- 4 files changed, 8 insertions(+), 9 deletions(-) diff --git a/doc/faq/howto_faq.rst b/doc/faq/howto_faq.rst index e2562eced83..b1e1eb4890b 100644 --- a/doc/faq/howto_faq.rst +++ b/doc/faq/howto_faq.rst @@ -191,7 +191,7 @@ specify the location explicitly:: ax = fig.add_axes([left, bottom, width, height]) where all values are in fractional (0 to 1) coordinates. See -:ref:`sphx_glr_gallery_pylab_examples_axes_demo.py` for an example of placing axes manually. +:ref:`sphx_glr_gallery_subplots_axes_and_figures_axes_demo.py` for an example of placing axes manually. .. _howto-auto-adjust: @@ -359,7 +359,7 @@ some ratio which controls the ratio:: .. htmlonly:: - See :ref:`sphx_glr_gallery_pylab_examples_axis_equal_demo.py` for a + See :ref:`sphx_glr_gallery_subplots_axes_and_figures_axis_equal_demo.py` for a complete example. .. _howto-twoscale: @@ -755,4 +755,3 @@ reference page `_):: development, interactive scripting, and publication-quality image generation across user interfaces and operating systems.}, Bdsk-Url-1 = {http://gateway.isiknowledge.com/gateway/Gateway.cgi?GWVersion=2&SrcAuth=Alerting&SrcApp=Alerting&DestApp=WOS&DestLinkType=FullRecord;KeyUT=000245668100019}} - diff --git a/examples/recipes/fill_between_alpha.py b/examples/recipes/fill_between_alpha.py index eb36d7b32a2..16216aedb17 100644 --- a/examples/recipes/fill_between_alpha.py +++ b/examples/recipes/fill_between_alpha.py @@ -133,4 +133,4 @@ # vertical spans of an axes -- for that matplotlib has some helper # functions :meth:`~matplotlib.axes.Axes.axhspan` and # :meth:`~matplotlib.axes.Axes.axvspan` and example -# :ref:`sphx_glr_gallery_pylab_examples_axhspan_demo.py`. +# :ref:`sphx_glr_gallery_subplots_axes_and_figures_axhspan_demo.py`. diff --git a/tutorials/01_introductory/pyplot.py b/tutorials/01_introductory/pyplot.py index 23f5604ed5a..47c86e4e4ae 100644 --- a/tutorials/01_introductory/pyplot.py +++ b/tutorials/01_introductory/pyplot.py @@ -277,7 +277,7 @@ def f(t): # rectangular grid, use the :func:`~matplotlib.pyplot.axes` command, # which allows you to specify the location as ``axes([left, bottom, # width, height])`` where all values are in fractional (0 to 1) -# coordinates. See :ref:`sphx_glr_gallery_pylab_examples_axes_demo.py` for an example of +# coordinates. See :ref:`sphx_glr_gallery_subplots_axes_and_figures_axes_demo.py` for an example of # placing axes manually and :ref:`sphx_glr_gallery_subplots_axes_and_figures_subplot_demo.py` for an # example with lots of subplots. # diff --git a/tutorials/text/annotations.py b/tutorials/text/annotations.py index 0bf520681de..1d9103a196a 100644 --- a/tutorials/text/annotations.py +++ b/tutorials/text/annotations.py @@ -284,8 +284,8 @@ ``wedge`` tail_width=0.3,shrink_factor=0.5 ========== ============================================= -.. figure:: ../../gallery/pylab_examples/images/sphx_glr_fancyarrow_demo_001.png - :target: ../../gallery/pylab_examples/fancyarrow_demo.html +.. figure:: ../../gallery/text_labels_and_annotations/images/sphx_glr_fancyarrow_demo_001.png + :target: ../../gallery/text_labels_and_annotations/fancyarrow_demo.html :align: center :scale: 50 @@ -557,8 +557,8 @@ straight forward. -.. figure:: ../../gallery/pylab_examples/images/sphx_glr_axes_zoom_effect_001.png - :target: ../../gallery/pylab_examples/axes_zoom_effect.html +.. figure:: ../../gallery/subplots_axes_and_figures/images/sphx_glr_axes_zoom_effect_001.png + :target: ../../gallery/subplots_axes_and_figures/axes_zoom_effect.html :align: center :scale: 50 From d690448f50848e374cc0c99a9631f908aa1bd61e Mon Sep 17 00:00:00 2001 From: David Stansby Date: Thu, 29 Jun 2017 18:17:30 +0100 Subject: [PATCH 3/4] Minor moved example fixes --- examples/subplots_axes_and_figures/axes_demo.py | 2 +- examples/subplots_axes_and_figures/axhspan_demo.py | 8 +++----- examples/text_labels_and_annotations/fancyarrow_demo.py | 1 - 3 files changed, 4 insertions(+), 7 deletions(-) diff --git a/examples/subplots_axes_and_figures/axes_demo.py b/examples/subplots_axes_and_figures/axes_demo.py index ee6bb512931..f243f8cb709 100644 --- a/examples/subplots_axes_and_figures/axes_demo.py +++ b/examples/subplots_axes_and_figures/axes_demo.py @@ -15,7 +15,7 @@ # create some data to use for the plot dt = 0.001 t = np.arange(0.0, 10.0, dt) -r = np.exp(-t[:1000] / 0.05) # impulse response +r = np.exp(-t[:1000] / 0.05) # impulse response x = np.random.randn(len(t)) s = np.convolve(x, r)[:len(x)] * dt # colored noise diff --git a/examples/subplots_axes_and_figures/axhspan_demo.py b/examples/subplots_axes_and_figures/axhspan_demo.py index ddf1a3706e9..29716e80056 100644 --- a/examples/subplots_axes_and_figures/axhspan_demo.py +++ b/examples/subplots_axes_and_figures/axhspan_demo.py @@ -1,6 +1,6 @@ """ ============ -Axhspan Demo +axhspan Demo ============ Create lines or rectangles that span the axes in either the horizontal or @@ -22,12 +22,10 @@ # Draw a default vline at x=1 that spans the yrange plt.axvline(x=1) -# Draw a thick blue vline at x=0 that spans the upper quadrant of -# the yrange +# Draw a thick blue vline at x=0 that spans the upper quadrant of the yrange plt.axvline(x=0, ymin=0.75, linewidth=8, color='#1f77b4') -# Draw a default hline at y=.5 that spans the middle half of -# the axes +# Draw a default hline at y=.5 that spans the middle half of the axes plt.axhline(y=.5, xmin=0.25, xmax=0.75) plt.axhspan(0.25, 0.75, facecolor='0.5', alpha=0.5) diff --git a/examples/text_labels_and_annotations/fancyarrow_demo.py b/examples/text_labels_and_annotations/fancyarrow_demo.py index 2a35d9212ab..6eb904433b6 100644 --- a/examples/text_labels_and_annotations/fancyarrow_demo.py +++ b/examples/text_labels_and_annotations/fancyarrow_demo.py @@ -37,7 +37,6 @@ def to_texstring(s): ax.annotate(to_texstring(stylename), (x, y), (x - 1.2, y), - # xycoords="figure fraction", textcoords="figure fraction", ha="right", va="center", size=fontsize, arrowprops=dict(arrowstyle=stylename, From 94bdcbe9d836553205d4d561669c75c3d78fd8da Mon Sep 17 00:00:00 2001 From: David Stansby Date: Sat, 1 Jul 2017 10:05:59 +0100 Subject: [PATCH 4/4] Fix link in tutorials --- tutorials/01_introductory/sample_plots.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tutorials/01_introductory/sample_plots.py b/tutorials/01_introductory/sample_plots.py index c4fedcbc4cb..f47c7bbe32a 100644 --- a/tutorials/01_introductory/sample_plots.py +++ b/tutorials/01_introductory/sample_plots.py @@ -143,7 +143,7 @@ Barchart Demo You can also create stacked bars -(`bar_stacked.py <../../gallery/pylab_examples/bar_stacked.html>`_), +(`bar_stacked.py <../../gallery/lines_bars_and_markers/bar_stacked.html>`_), or horizontal bar charts (`barh.py <../../gallery/lines_bars_and_markers/barh.html>`_).