diff --git a/examples/api/barchart_demo.py b/examples/api/barchart_demo.py deleted file mode 100644 index e3d89b417752..000000000000 --- a/examples/api/barchart_demo.py +++ /dev/null @@ -1,39 +0,0 @@ - -#!/usr/bin/env python -# a bar plot with errorbars -import numpy as np -import matplotlib.pyplot as plt - -N = 5 -menMeans = (20, 35, 30, 35, 27) -menStd = (2, 3, 4, 1, 2) - -ind = np.arange(N) # the x locations for the groups -width = 0.35 # the width of the bars - -fig, ax = plt.subplots() -rects1 = ax.bar(ind, menMeans, width, color='r', yerr=menStd) - -womenMeans = (25, 32, 34, 20, 25) -womenStd = (3, 5, 2, 3, 3) -rects2 = ax.bar(ind+width, womenMeans, width, color='y', yerr=womenStd) - -# add some text for labels, title and axes ticks -ax.set_ylabel('Scores') -ax.set_title('Scores by group and gender') -ax.set_xticks(ind+width) -ax.set_xticklabels( ('G1', 'G2', 'G3', 'G4', 'G5') ) - -ax.legend( (rects1[0], rects2[0]), ('Men', 'Women') ) - -def autolabel(rects): - # attach some text labels - for rect in rects: - height = rect.get_height() - ax.text(rect.get_x()+rect.get_width()/2., 1.05*height, '%d'%int(height), - ha='center', va='bottom') - -autolabel(rects1) -autolabel(rects2) - -plt.show() diff --git a/examples/api/fahrenheit_celsius_scales.py b/examples/api/fahrenheit_celsius_scales.py deleted file mode 100644 index 72a52f4fa41b..000000000000 --- a/examples/api/fahrenheit_celsius_scales.py +++ /dev/null @@ -1,27 +0,0 @@ -""" -Show how to display two scales on the left and right y axis -- Fahrenheit and Celsius -""" - -import matplotlib.pyplot as plt - -fig, ax1 = plt.subplots() # ax1 is the Fahrenheit scale -ax2 = ax1.twinx() # ax2 is the Celsius scale - -def Tc(Tf): - return (5./9.)*(Tf-32) - - -def update_ax2(ax1): - y1, y2 = ax1.get_ylim() - ax2.set_ylim(Tc(y1), Tc(y2)) - ax2.figure.canvas.draw() - -# automatically update ylim of ax2 when ylim of ax1 changes. -ax1.callbacks.connect("ylim_changed", update_ax2) -ax1.plot([78, 79, 79, 77]) - -ax1.set_title('Two scales: Fahrenheit and Celsius') -ax1.set_ylabel('Fahrenheit') -ax2.set_ylabel('Celsius') - -plt.show() diff --git a/examples/statistics/barchart_demo.py b/examples/statistics/barchart_demo.py new file mode 100644 index 000000000000..f16f695c61b1 --- /dev/null +++ b/examples/statistics/barchart_demo.py @@ -0,0 +1,13 @@ +""" +Demo of multiple bar plots. +""" +import matplotlib.pyplot as plt + +values = (20, 35, 30, 35, 27) +pos = (0, 1, 2, 3, 4) + +plt.bar(left=pos, height=values, width=0.5, color='r') + +plt.title('Example of bar plots') + +plt.show() diff --git a/examples/statistics/barchart_demo_error.py b/examples/statistics/barchart_demo_error.py new file mode 100644 index 000000000000..3cf07b9bdf35 --- /dev/null +++ b/examples/statistics/barchart_demo_error.py @@ -0,0 +1,14 @@ +""" +Demo of multiple bar plot with errorbars +""" +import matplotlib.pyplot as plt + +values = (20, 35, 30, 35, 27) +errors = (2, 3, 4, 1, 2) +pos = (0, 1, 2, 3, 4) + +plt.bar(left=pos, height=values, width=0.5, color='r', yerr=errors) + +plt.title("Bar plot with errors") + +plt.show() diff --git a/examples/subplots_axes_and_figures/fahrenheit_celsius_scales.py b/examples/subplots_axes_and_figures/fahrenheit_celsius_scales.py new file mode 100644 index 000000000000..2318f1678671 --- /dev/null +++ b/examples/subplots_axes_and_figures/fahrenheit_celsius_scales.py @@ -0,0 +1,37 @@ +""" +Demo of how to display two scales on the left and right y axis. + +This example uses the Fahrenheit and Celsius scales. +""" +import matplotlib.pyplot as plt +import numpy as np + + +def fahrenheit2celsius(temp): + """ + Returns temperature in Celsius. + """ + return (5. / 9.) * (temp - 32) + + +def convert_ax_c_to_celsius(ax_f): + """ + Update second axis according with first axis. + """ + y1, y2 = ax_f.get_ylim() + ax_c.set_ylim(fahrenheit2celsius(y1), fahrenheit2celsius(y2)) + ax_c.figure.canvas.draw() + +fig, ax_f = plt.subplots() +ax_c = ax_f.twinx() + +# automatically update ylim of ax2 when ylim of ax1 changes. +ax_f.callbacks.connect("ylim_changed", convert_ax_c_to_celsius) +ax_f.plot(np.linspace(-40, 120, 100)) +ax_f.set_xlim(0, 100) + +ax_f.set_title('Two scales: Fahrenheit and Celsius') +ax_f.set_ylabel('Fahrenheit') +ax_c.set_ylabel('Celsius') + +plt.show()