From 5569802bf473c49ea9c30aa8868216fa05bde212 Mon Sep 17 00:00:00 2001 From: Diego Leal Date: Sat, 22 Aug 2020 02:35:25 -0300 Subject: [PATCH] Moved the files and deleted `Our Favorite Recipes` section - Adjusted linking problems due to filmes moved - Updated date.py to give just a bit more info since common_date_problems.py was deleted --- examples/axisartist/demo_axisline_style.py | 4 +- .../fill_between_alpha.py | 0 examples/recipes/README.txt | 8 -- examples/recipes/common_date_problems.py | 73 ------------------- .../share_axis_lims_views.py | 0 examples/text_labels_and_annotations/date.py | 27 ++++--- .../placing_text_boxes.py | 0 .../centered_spines_with_arrows.py | 0 .../ticks_and_spines/spine_placement_demo.py | 2 +- examples/widgets/textbox.py | 2 +- 10 files changed, 20 insertions(+), 96 deletions(-) rename examples/{recipes => lines_bars_and_markers}/fill_between_alpha.py (100%) delete mode 100644 examples/recipes/README.txt delete mode 100644 examples/recipes/common_date_problems.py rename examples/{recipes => subplots_axes_and_figures}/share_axis_lims_views.py (100%) rename examples/{recipes => text_labels_and_annotations}/placing_text_boxes.py (100%) rename examples/{recipes => ticks_and_spines}/centered_spines_with_arrows.py (100%) diff --git a/examples/axisartist/demo_axisline_style.py b/examples/axisartist/demo_axisline_style.py index e3159c9c054f..6864de5a2f9c 100644 --- a/examples/axisartist/demo_axisline_style.py +++ b/examples/axisartist/demo_axisline_style.py @@ -7,8 +7,8 @@ Note: The `mpl_toolkits.axisartist` axes classes may be confusing for new users. If the only aim is to obtain arrow heads at the ends of the axes, -rather check out the :doc:`/gallery/recipes/centered_spines_with_arrows` -example. +rather check out the +:doc:`/gallery/ticks_and_spines/centered_spines_with_arrows` example. """ from mpl_toolkits.axisartist.axislines import SubplotZero diff --git a/examples/recipes/fill_between_alpha.py b/examples/lines_bars_and_markers/fill_between_alpha.py similarity index 100% rename from examples/recipes/fill_between_alpha.py rename to examples/lines_bars_and_markers/fill_between_alpha.py diff --git a/examples/recipes/README.txt b/examples/recipes/README.txt deleted file mode 100644 index 63a3ca0d4e56..000000000000 --- a/examples/recipes/README.txt +++ /dev/null @@ -1,8 +0,0 @@ -.. _recipes: - -Our Favorite Recipes -==================== - -Here is a collection of short tutorials, examples and code snippets -that illustrate some of the useful idioms and tricks to make snazzier -figures and overcome some matplotlib warts. diff --git a/examples/recipes/common_date_problems.py b/examples/recipes/common_date_problems.py deleted file mode 100644 index 0218c9327430..000000000000 --- a/examples/recipes/common_date_problems.py +++ /dev/null @@ -1,73 +0,0 @@ -""" -Fixing common date annoyances -============================= - -Matplotlib allows you to natively plots python datetime instances, and -for the most part does a good job picking tick locations and string -formats. There are a couple of things it does not handle so -gracefully, and here are some tricks to help you work around them. -We'll load up some sample date data which contains datetime.date -objects in a numpy record array:: - - In [63]: datafile = cbook.get_sample_data('goog.npz') - - In [64]: r = np.load(datafile)['price_data'].view(np.recarray) - - In [65]: r.dtype - Out[65]: dtype([('date', '] - -you will see that the x tick labels are all squashed together. -""" -import matplotlib.cbook as cbook -import matplotlib.dates as mdates -import numpy as np -import matplotlib.pyplot as plt - -r = (cbook.get_sample_data('goog.npz', np_load=True)['price_data'] - .view(np.recarray)) - -fig, ax = plt.subplots() -ax.plot(r.date, r.close) -ax.set_title('Default date handling can cause overlapping labels') - -############################################################################### -# Another annoyance is that if you hover the mouse over the window and look in -# the lower right corner of the Matplotlib toolbar (:ref:`navigation-toolbar`) -# at the x and y coordinates, you see that the x locations are formatted the -# same way the tick labels are, e.g., "Dec 2004". -# -# What we'd like is for the location in the toolbar to have a higher degree of -# precision, e.g., giving us the exact date out mouse is hovering over. To fix -# the first problem, we can use `.Figure.autofmt_xdate` and to fix the second -# problem we can use the ``ax.fmt_xdata`` attribute which can be set to any -# function that takes a scalar and returns a string. Matplotlib has a number -# of date formatters built in, so we'll use one of those. - -fig, ax = plt.subplots() -ax.plot(r.date, r.close) -# Rotate and align the tick labels so they look better. -fig.autofmt_xdate() -# Use a more precise date string for the x axis locations in the toolbar. -ax.fmt_xdata = mdates.DateFormatter('%Y-%m-%d') -ax.set_title('fig.autofmt_xdate fixes the labels') - -############################################################################### -# Now when you hover your mouse over the plotted data, you'll see date -# format strings like 2004-12-01 in the toolbar. - -plt.show() diff --git a/examples/recipes/share_axis_lims_views.py b/examples/subplots_axes_and_figures/share_axis_lims_views.py similarity index 100% rename from examples/recipes/share_axis_lims_views.py rename to examples/subplots_axes_and_figures/share_axis_lims_views.py diff --git a/examples/text_labels_and_annotations/date.py b/examples/text_labels_and_annotations/date.py index 393b925f026a..b2aedebcbfb2 100644 --- a/examples/text_labels_and_annotations/date.py +++ b/examples/text_labels_and_annotations/date.py @@ -14,6 +14,9 @@ provides the converter functions `.date2num` and `.num2date`, which convert `datetime.datetime` and `numpy.datetime64` objects to and from Matplotlib's internal representation. + +An alternative way of displaying dates can be seen at +:doc:`/gallery/ticks_and_spines/date_concise_formatter`. """ import numpy as np @@ -21,10 +24,6 @@ import matplotlib.dates as mdates import matplotlib.cbook as cbook -years = mdates.YearLocator() # every year -months = mdates.MonthLocator() # every month -years_fmt = mdates.DateFormatter('%Y') - # Load a numpy structured array from yahoo csv data with fields date, open, # close, volume, adj_close from the mpl-data/example directory. This array # stores the date as an np.datetime64 with a day unit ('D') in the 'date' @@ -34,18 +33,24 @@ fig, ax = plt.subplots() ax.plot('date', 'adj_close', data=data) -# format the ticks -ax.xaxis.set_major_locator(years) -ax.xaxis.set_major_formatter(years_fmt) -ax.xaxis.set_minor_locator(months) +# Major ticks every 6 months +fmt_half_year = mdates.MonthLocator(interval=6) +ax.xaxis.set_major_locator(fmt_half_year) + +# Minor ticks every month +fmt_month = mdates.MonthLocator() +ax.xaxis.set_minor_locator(fmt_month) + +# Text in the x axis will be displayed in 'YYYY-mm' format +ax.xaxis.set_major_formatter(mdates.DateFormatter('%Y-%m')) -# round to nearest years. +# Round to nearest years. datemin = np.datetime64(data['date'][0], 'Y') datemax = np.datetime64(data['date'][-1], 'Y') + np.timedelta64(1, 'Y') ax.set_xlim(datemin, datemax) -# format the coords message box -ax.format_xdata = mdates.DateFormatter('%Y-%m-%d') +# Format the coords message box +ax.format_xdata = mdates.DateFormatter('%Y-%m') ax.format_ydata = lambda x: '$%1.2f' % x # format the price. ax.grid(True) diff --git a/examples/recipes/placing_text_boxes.py b/examples/text_labels_and_annotations/placing_text_boxes.py similarity index 100% rename from examples/recipes/placing_text_boxes.py rename to examples/text_labels_and_annotations/placing_text_boxes.py diff --git a/examples/recipes/centered_spines_with_arrows.py b/examples/ticks_and_spines/centered_spines_with_arrows.py similarity index 100% rename from examples/recipes/centered_spines_with_arrows.py rename to examples/ticks_and_spines/centered_spines_with_arrows.py diff --git a/examples/ticks_and_spines/spine_placement_demo.py b/examples/ticks_and_spines/spine_placement_demo.py index 8c79da343430..b831209abad3 100644 --- a/examples/ticks_and_spines/spine_placement_demo.py +++ b/examples/ticks_and_spines/spine_placement_demo.py @@ -6,7 +6,7 @@ Adjusting the location and appearance of axis spines. Note: If you want to obtain arrow heads at the ends of the axes, also check -out the :doc:`/gallery/recipes/centered_spines_with_arrows` example. +out the :doc:`/gallery/ticks_and_spines/centered_spines_with_arrows` example. """ import numpy as np import matplotlib.pyplot as plt diff --git a/examples/widgets/textbox.py b/examples/widgets/textbox.py index c61ef74e4a7d..4e65af7bd9a1 100644 --- a/examples/widgets/textbox.py +++ b/examples/widgets/textbox.py @@ -10,7 +10,7 @@ Note: The `matplotlib.widgets.TextBox` widget is different from the following static elements: :doc:`/tutorials/text/annotations` and -:doc:`/gallery/recipes/placing_text_boxes`. +:doc:`/gallery/text_labels_and_annotations/placing_text_boxes`. """ import numpy as np