From 19c8e1aece446439ace920d430dffccb5c87258d Mon Sep 17 00:00:00 2001 From: Chris Holdgraf Date: Fri, 14 Jul 2017 14:22:41 -0500 Subject: [PATCH] adding auto ticks example --- examples/ticks_and_spines/auto_ticks.py | 46 +++++++++++++++++++++++++ 1 file changed, 46 insertions(+) create mode 100644 examples/ticks_and_spines/auto_ticks.py diff --git a/examples/ticks_and_spines/auto_ticks.py b/examples/ticks_and_spines/auto_ticks.py new file mode 100644 index 000000000000..7cf1cc01615f --- /dev/null +++ b/examples/ticks_and_spines/auto_ticks.py @@ -0,0 +1,46 @@ +""" +================================= +Automatically setting tick labels +================================= + +Setting the behavior of tick auto-placement. + +If you don't explicitly set tick positions / labels, Matplotlib will attempt +to choose them both automatically based on the displayed data and its limits. + +By default, this attempts to choose tick positions that are distributed +along the axis: +""" +import matplotlib.pyplot as plt +import numpy as np +np.random.seed(19680801) + +fig, ax = plt.subplots() +dots = np.arange(10) / 100. + .03 +x, y = np.meshgrid(dots, dots) +data = [x.ravel(), y.ravel()] +ax.scatter(*data, c=data[1]) + +################################################################################ +# Sometimes choosing evenly-distributed ticks results in strange tick numbers. +# If you'd like Matplotlib to keep ticks located at round numbers, you can +# change this behavior with the following rcParams value: + +print(plt.rcParams['axes.autolimit_mode']) + +# Now change this value and see the results +with plt.rc_context({'axes.autolimit_mode': 'round_numbers'}): + fig, ax = plt.subplots() + ax.scatter(*data, c=data[1]) + +################################################################################ +# You can also alter the margins of the axes around the data by +# with ``axes.(x,y)margin``: + +with plt.rc_context({'axes.autolimit_mode': 'round_numbers', + 'axes.xmargin': .8, + 'axes.ymargin': .8}): + fig, ax = plt.subplots() + ax.scatter(*data, c=data[1]) + +plt.show() pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy