logo资料库

Python Graphics.pdf

第1页 / 共365页
第2页 / 共365页
第3页 / 共365页
第4页 / 共365页
第5页 / 共365页
第6页 / 共365页
第7页 / 共365页
第8页 / 共365页
资料共365页,剩余部分请下载后查看
Table of Contents
About the Author
About the Technical Reviewer
Acknowledgments
Chapter 1: Essential Python Commands and Functions
1.1 Programming Style
1.2 The Plotting Area
1.3 Establishing the Size of the Plotting Area
1.4 Importing Plotting Commands
1.5 Displaying the Plotting Area
1.6 The Plotting Grid
1.7 Saving a Plot
1.8 Grid Color
1.9 Tick Marks
1.10 Custom Grid Lines
1.11 Labelling the Axes
1.12 The Plot Title
1.13 Colors
1.13.1 Color Mixing
1.13.2 Color Intensity
1.14 Overplotting
1.15 Background Color
1.16 The Plotting Area Shape
1.17 How to Correct Shape Distortions
1.17.1 Applying a Scale Factor When Plotting
1.17.2 The Best Way: Scaling the Axes in plt.axis()
1.18 Coordinate Axes
1.19 Commonly Used Plotting Commands and Functions
1.19.1 Points and Dots Using scatter()
1.19.2 Lines Using plot()
1.19.3 Arrows
1.19.4 Text
1.19.5 Lists, Tuples, and Arrays
1.19.6 Arrays
1.19.7 arange( )
1.19.8 range( )
1.20 Summary
Chapter 2: Graphics in Two Dimensions
2.1 Lines from Dots
2.2 Dot Art
2.3 Circular Arcs from Dots
2.4 Circular Arcs from Line Segments
2.5 Circles
2.6 Dot Discs
2.7 Ellipses
2.8 2D Translation
2.9 2D Rotation
2.10 Summary
Chapter 3: Graphics in Three Dimensions
3.1 The Three-Dimensional Coordinate System
3.2 Projections onto the Coordinate Planes
3.3 Rotation Around the y Direction
3.4 Rotation Around the x Direction
3.5 Rotation Around the z Direction
3.6 Separate Rotations Around the Coordinate Directions
3.7 Sequential Rotations Around the Coordinate Directions
3.8 Matrix Concatenation
3.9 Keyboard Data Entry with Functional Program Structure
3.10 Summary
Chapter 4: Perspective
4.1 Summary
Chapter 5: Intersections
5.1 Line Intersecting a Rectangular Plane
5.2 Line Intersecting a Triangular Plane
5.3 Line Intersecting a Circle
5.4 Line Intersecting a Circular Sector
5.5 Line Intersecting a Sphere
5.6 Plane Intersecting a Sphere
5.7 Summary
Chapter 6: Hidden Line Removal
6.1 Box
6.2 Pyramid
6.3 Planes
6.4 Sphere
6.5 Summary
Chapter 7: Shading
7.1 Shading a Box
7.2 Shading a Sphere
7.3 Summary
Chapter 8: 2D Data Plotting
8.1 Linear Regression
8.2 Function Fitting
8.3 Splines
8.4 Summary
Chapter 9: 3D Data Plotting
9.1 3D Surfaces
9.2 3D Surface Shading
9.3 Summary
Chapter 10: Demonstrations
10.1 Saturn
10.2 Solar Radiation
10.2.1 Photons and the Sun
10.2.2 Max Planck’s Black Body Radiation
10.2.3 The Sun’s Total Power Output
10.3 Earth’s Irradiance
10.3.1 The Earth Sun Model
10.4 Summary
Appendix A: Where to Get Python
Appendix B: Planck’s Radiation Law and the Stefan-Boltzmann Equation
Index
Python Graphics A Reference for Creating 2D and 3D Images — B.J. Korites www.allitebooks.com
Python Graphics A Reference for Creating 2D and 3D Images B.J. Korites www.allitebooks.com
Python Graphics B.J. Korites Duxbury, Massachusetts, USA ISBN-13 (pbk): 978-1-4842-3377-1 https://doi.org/10.1007/978-1-4842-3378-8 Library of Congress Control Number: 2018946635 ISBN-13 (electronic): 978-1-4842-3378-8 Copyright © 2018 by B.J. Korites This work is subject to copyright. All rights are reserved by the Publisher, whether the whole or part of the material is concerned, specifically the rights of translation, reprinting, reuse of illustrations, recitation, broadcasting, reproduction on microfilms or in any other physical way, and transmission or information storage and retrieval, electronic adaptation, computer software, or by similar or dissimilar methodology now known or hereafter developed. Trademarked names, logos, and images may appear in this book. Rather than use a trademark symbol with every occurrence of a trademarked name, logo, or image we use the names, logos, and images only in an editorial fashion and to the benefit of the trademark owner, with no intention of infringement of the trademark. The use in this publication of trade names, trademarks, service marks, and similar terms, even if they are not identified as such, is not to be taken as an expression of opinion as to whether or not they are subject to proprietary rights. While the advice and information in this book are believed to be true and accurate at the date of publication, neither the authors nor the editors nor the publisher can accept any legal responsibility for any errors or omissions that may be made. The publisher makes no warranty, express or implied, with respect to the material contained herein. Managing Director, Apress Media LLC: Welmoed Spahr Acquisitions Editor: Todd Green Development Editor: James Markham Coordinating Editor: Jill Balzano Cover designed by eStudioCalamar Cover image designed by Freepik (www.freepik.com) Distributed to the book trade worldwide by Springer Science+Business Media New York, 233 Spring Street, 6th Floor, New York, NY 10013. Phone 1-800-SPRINGER, fax (201) 348-4505, e-mail orders-ny@springer- sbm.com, or visit www.springeronline.com. Apress Media, LLC is a California LLC and the sole member (owner) is Springer Science + Business Media Finance Inc (SSBM Finance Inc). SSBM Finance Inc is a Delaware corporation. For information on translations, please e-mail rights@apress.com, or visit www.apress.com/ rights-permissions. Apress titles may be purchased in bulk for academic, corporate, or promotional use. eBook versions and licenses are also available for most titles. For more information, reference our Print and eBook Bulk Sales web page at www.apress.com/bulk-sales. Any source code or other supplementary material referenced by the author in this book is available to readers on GitHub via the book’s product page, located at www.apress.com/9781484233771. For more detailed information, please visit www.apress.com/source-code. Printed on acid-free paper www.allitebooks.com
For Pam www.allitebooks.com
Table of Contents About the Author ����������������������������������������������������������������������������������������������������� ix About the Technical Reviewer ��������������������������������������������������������������������������������� xi Acknowledgments ������������������������������������������������������������������������������������������������� xiii Chapter 1: Essential Python Commands and Functions ������������������������������������������� 1 1.1 Programming Style ................................................................................................................. 2 1.2 The Plotting Area ..................................................................................................................... 3 1.3 Establishing the Size of the Plotting Area ............................................................................... 4 1.4 Importing Plotting Commands ................................................................................................ 6 1.5 Displaying the Plotting Area .................................................................................................... 8 1.6 The Plotting Grid ...................................................................................................................... 8 1.7 Saving a Plot ........................................................................................................................... 8 1.8 Grid Color ................................................................................................................................ 9 1.9 Tick Marks ............................................................................................................................... 9 1.10 Custom Grid Lines ............................................................................................................... 11 1.11 Labelling the Axes ............................................................................................................... 13 1.12 The Plot Title ....................................................................................................................... 14 1.13 Colors .................................................................................................................................. 15 1.13.1 Color Mixing ................................................................................................................ 16 1.13.2 Color Intensity............................................................................................................. 19 1.14 Overplotting ........................................................................................................................ 20 1.15 Background Color ............................................................................................................... 23 1.16 The Plotting Area Shape ...................................................................................................... 23 1.17 How to Correct Shape Distortions ....................................................................................... 26 1.17.1 Applying a Scale Factor When Plotting ....................................................................... 27 1.17.2 The Best Way: Scaling the Axes in plt.axis( ) ............................................................... 27 v www.allitebooks.com
Table of ConTenTs 1.18 Coordinate Axes .................................................................................................................. 29 1.19 Commonly Used Plotting Commands and Functions .......................................................... 30 1.19.1 Points and Dots Using scatter( ) .................................................................................. 31 1.19.2 Lines Using plot( ) ....................................................................................................... 32 1.19.3 Arrows ........................................................................................................................ 33 1.19.4 Text ............................................................................................................................. 34 1.19.5 Lists, Tuples, and Arrays ............................................................................................. 36 1.19.6 Arrays ......................................................................................................................... 41 1.19.7 arange( ) ..................................................................................................................... 42 1.19.8 range( ) ....................................................................................................................... 43 1.20 Summary............................................................................................................................. 43 Chapter 2: Graphics in Two Dimensions ���������������������������������������������������������������� 45 2.1 Lines from Dots ..................................................................................................................... 45 2.2 Dot Art ................................................................................................................................... 50 2.3 Circular Arcs from Dots ......................................................................................................... 52 2.4 Circular Arcs from Line Segments ........................................................................................ 59 2.5 Circles ................................................................................................................................... 60 2.6 Dot Discs ............................................................................................................................... 64 2.7 Ellipses .................................................................................................................................. 68 2.8 2D Translation ....................................................................................................................... 75 2.9 2D Rotation ........................................................................................................................... 78 2.10 Summary........................................................................................................................... 100 Chapter 3: Graphics in Three Dimensions ������������������������������������������������������������ 101 3.1 The Three-Dimensional Coordinate System ........................................................................ 101 3.2 Projections onto the Coordinate Planes .............................................................................. 104 3.3 Rotation Around the y Direction .......................................................................................... 106 3.4 Rotation Around the x Direction .......................................................................................... 109 3.5 Rotation Around the z Direction .......................................................................................... 111 3.6 Separate Rotations Around the Coordinate Directions ........................................................ 113 3.7 Sequential Rotations Around the Coordinate Directions ..................................................... 121 vi
Table of ConTenTs 3.8 Matrix Concatenation .......................................................................................................... 129 3.9 Keyboard Data Entry with Functional Program Structure ................................................... 133 3.10 Summary........................................................................................................................... 141 Chapter 4: Perspective ����������������������������������������������������������������������������������������� 143 4.1 Summary............................................................................................................................. 152 Chapter 5: Intersections ��������������������������������������������������������������������������������������� 153 5.1 Line Intersecting a Rectangular Plane ................................................................................ 153 5.2 Line Intersecting a Triangular Plane .................................................................................... 166 5.3 Line Intersecting a Circle .................................................................................................... 181 5.4 Line Intersecting a Circular Sector ...................................................................................... 181 5.5 Line Intersecting a Sphere .................................................................................................. 187 5.6 Plane Intersecting a Sphere ................................................................................................ 196 5.7 Summary............................................................................................................................. 201 Chapter 6: Hidden Line Removal ��������������������������������������������������������������������������� 203 6.1 Box ...................................................................................................................................... 203 6.2 Pyramid ............................................................................................................................... 212 6.3 Planes ................................................................................................................................. 218 6.4 Sphere ................................................................................................................................. 225 6.5 Summary............................................................................................................................. 233 Chapter 7: Shading ����������������������������������������������������������������������������������������������� 235 7.1 Shading a Box ..................................................................................................................... 236 7.2 Shading a Sphere ................................................................................................................ 246 7.3 Summary............................................................................................................................. 253 Chapter 8: 2D Data Plotting ���������������������������������������������������������������������������������� 255 8.1 Linear Regression ............................................................................................................... 265 8.2 Function Fitting ................................................................................................................... 269 8.3 Splines ................................................................................................................................ 275 8.4 Summary............................................................................................................................. 283 vii
Table of ConTenTs Chapter 9: 3D Data Plotting ���������������������������������������������������������������������������������� 285 9.1 3D Surfaces......................................................................................................................... 297 9.2 3D Surface Shading ............................................................................................................ 305 9.3 Summary............................................................................................................................. 319 Chapter 10: Demonstrations ��������������������������������������������������������������������������������� 321 10.1 Saturn ............................................................................................................................... 321 10.2 Solar Radiation .................................................................................................................. 331 10.2.1 Photons and the Sun ................................................................................................ 331 10.2.2 Max Planck’s Black Body Radiation .......................................................................... 333 10.2.3 The Sun’s Total Power Output ................................................................................... 334 10.3 Earth’s Irradiance .............................................................................................................. 344 10.3.1 The Earth Sun Model ................................................................................................ 346 10.4 Summary........................................................................................................................... 351 Appendix A: Where to Get Python ������������������������������������������������������������������������� 353 Appendix B: Planck’s Radiation Law and the Stefan-Boltzmann Equation ����������� 355 Index ��������������������������������������������������������������������������������������������������������������������� 359 viii
分享到:
收藏