Search icon CANCEL
Subscription
0
Cart icon
Your Cart (0 item)
Close icon
You have no products in your basket yet
Arrow left icon
Explore Products
Best Sellers
New Releases
Books
Videos
Audiobooks
Learning Hub
Conferences
Free Learning
Arrow right icon
Arrow up icon
GO TO TOP
SciPy Recipes

You're reading from   SciPy Recipes A cookbook with over 110 proven recipes for performing mathematical and scientific computations

Arrow left icon
Product type Paperback
Published in Dec 2017
Publisher Packt
ISBN-13 9781788291460
Length 386 pages
Edition 1st Edition
Languages
Tools
Arrow right icon
Authors (3):
Arrow left icon
V Kishore Ayyadevara V Kishore Ayyadevara
Author Profile Icon V Kishore Ayyadevara
V Kishore Ayyadevara
Ruben Oliva Ramos Ruben Oliva Ramos
Author Profile Icon Ruben Oliva Ramos
Ruben Oliva Ramos
Luiz Felipe Martins Luiz Felipe Martins
Author Profile Icon Luiz Felipe Martins
Luiz Felipe Martins
Arrow right icon
View More author details
Toc

Table of Contents (11) Chapters Close

Preface 1. Getting to Know the Tools FREE CHAPTER 2. Getting Started with NumPy 3. Using Matplotlib to Create Graphs 4. Data Wrangling with pandas 5. Matrices and Linear Algebra 6. Solving Equations and Optimization 7. Constants and Special Functions 8. Calculus, Interpolation, and Differential Equations 9. Statistics and Probability 10. Advanced Computations with SciPy

Running SciPy in Spyder

Spyder—which is an acronym for Scientific PYthon Development EnviRonment—is an IDE specifically designed for Python and SciPy. It provides an out-of-the box solution for developing projects that use NumPy, SciPy, pandas, and other scientific or data-oriented Python libraries.

Getting ready

Spyder is included in the default Anaconda distribution, so, if you are using Anaconda, you already have Spyder.

If not, you can install it with pip using the following commands:

pip3 install PyQt5
pip3 install spyder

Note that depending on your configuration, you may already have PyQt5 installed, but attempting to install it again will do no harm. pip3 will only tell you that the package is already present.

How to do it...

The first step is to start Spyder by running the following command from the command line:

spyder

After a few moments, the Spyder home window will appear on your screen, displaying an environment similar to the one shown in the following screenshot:

The window shown contains the following panes:

  • On the left side of the window is the the Editor pane, where you enter code.
  • The top right pane is the inspector pane. This pane is used to display information about code objects.
  • The bottom right pane is the console pane. Notice that you can choose between an IPython console, a plain Python console, and the History Log.

To test the running code in Spyder, remove all text from the Editor window and type in the following code:

import numpy as np
import matplotlib.pyplot as plt
from scipy.special import eval_chebyt

fig = plt.figure()
xvalues = np.linspace(-1, 1, 300)
nmax = 5
for n in range(nmax+1):
yvalues = eval_chebyt(n, xvalues)
plt.plot(xvalues, yvalues)
plt.title('Chebyshev polynomials $T_n(x)$ for $n=0,\\ldots,{}$'.format(nmax))
plt.axhline(0, color='gray')
plt.axvline(0, color='gray')
plt.xlabel('$x$')
plt.ylabel('$T_n(x)$')

print('Displaying graph')
plt.show()

This code first imports NumPy, pyplot, and the special eval_chebyt function, which computes the values of Chebyshev polynomials of the first kind. Chebyshev polynomials are a family of orthogonal polynomials that are important in the design of some numerical methods. Then, the code defines a figure object, stored in the variable fig. Then it computes arrays containing values of the first six Chebyshev polynomials and plots them in the figure, which is then displayed after the formatting of the title and labels on the graph.

To run the code, go to the Spyder menu and select Run-Configure. The following window with configuration options will pop up on the screen:

In the Console section, choose Execute in a new dedicated Python console, and leave all other options with their default values. Click OK to dismiss the box. Now, back in the main Spyder window, choose Run-Run on the menu, or press F5. The script will be launched and, after a few seconds, a window with a plot of the Chebyshev polynomials will be displayed. Closing the graph window will continue the execution of the script.

Spyder is a powerful yet simple to use IDE. To explore the features of Spyder, the reader is encouraged to explore the software's official documentation: https://pythonhosted.org/spyder/.

You have been reading a chapter from
SciPy Recipes
Published in: Dec 2017
Publisher: Packt
ISBN-13: 9781788291460
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 $19.99/month. Cancel anytime
Banner background image