Search icon
Arrow left icon
All Products
Best Sellers
New Releases
Books
Videos
Audiobooks
Learning Hub
Newsletters
Free Learning
Arrow right icon
Python Data Visualization Cookbook (Second Edition)

You're reading from  Python Data Visualization Cookbook (Second Edition)

Product type Book
Published in Nov 2015
Publisher
ISBN-13 9781784396695
Pages 302 pages
Edition 1st Edition
Languages

Table of Contents (16) Chapters

Python Data Visualization Cookbook Second Edition
Credits
About the Authors
About the Reviewer
www.PacktPub.com
Preface
Preparing Your Working Environment Knowing Your Data Drawing Your First Plots and Customizing Them More Plots and Customizations Making 3D Visualizations Plotting Charts with Images and Maps Using the Right Plots to Understand Data More on matplotlib Gems Visualizations on the Clouds with Plot.ly Index

Moving spines to the center


This recipe will demonstrate how to move spines to the center.

Spines define data area boundaries; they connect the axis tick marks. There are four spines. We can place them wherever we want; by default, they are placed on the border of the axis, hence we see a box around our data plot.

How to do it...

To move the spines to the center of the plot, we need to remove two spines, making them hidden (set color to none). After that, we move two others to coordinate (0,0). The coordinates are specified in data space coordinates.

The following code shows how to do this:

import matplotlib.pyplot as plt
import numpy as np

x = np.linspace(-np.pi, np.pi, 500, endpoint=True)
y = np.sin(x)

plt.plot(x, y)

ax = plt.gca()

# hide two spines
ax.spines['right'].set_color('none')
ax.spines['top'].set_color('none')

# move bottom and left spine to 0,0
ax.spines['bottom'].set_position(('data',0))
ax.spines['left'].set_position(('data',0))

# move ticks positions
ax.xaxis.set_ticks_position...
lock icon The rest of the chapter is locked
Register for a free Packt account to unlock a world of extra content!
A free Packt account unlocks extra newsletters, articles, discounted offers, and much more. Start advancing your knowledge today.
Unlock this book and the full library FREE for 7 days
Get unlimited access to 7000+ expert-authored eBooks and videos courses covering every tech area you can think of
Renews at $15.99/month. Cancel anytime}