Chapter 15
===
- [Installing matplotlib](#installing-matplotlib)
- [Checking if matplotlib is already installed](#checking-if-matplotlib-is-already-installed)
- [Installing matplotlib on Linux](#installing-matplotlib-on-linux)
- [Installing matplotlib on OS X](#installing-matplotlib-on-os-x)
- [Installing matplotlib on Windows](#installing-matplotlib-on-windows)
- [Installing Pygal](#installing-pygal)
- [Updates](#updates)
Installing matplotlib
---
There are many different ways to install matplotlib to your system. In this section, I'll recommend one method for each operating system. If you'd like to see the kinds of visualizations you can make with matplotlib, see the official matplotlib [sample gallery](http://matplotlib.org/gallery.html). When you click a visualization in the gallery, you can see the code used to generate the plot.
### Checking if matplotlib is already installed
First, check if matplotlib is already installed on your system:
$ python
>>> import matplotlib
>>>
If you don't see an error message, then matplotlib is already installed on your system and you should be able to get started right away on this chapter's projects. If you get an error message, read the appropriate section below for help installing matplotlib on your operating system.
Installing matplotlib on Linux
---
If you're using the version of Python that came with your system, you can use your system's package manager to install matplotlib in one line. For Python 3, this is:
$ sudo apt-get install python3-matplotlib
If you're using Python 2.7, this is:
$ sudo apt-get install python-matplotlib
If you installed a newer version of Python, you'll have to install several libraries that matplotlib depends on:
$ sudo apt-get install python3.5-dev python3.5-tk tk-dev
$ sudo apt-get install libfreetype6-dev g++
Then use pip to install matplotlib:
$ pip install --user matplotlib
If you need help using pip, see the <a href="../chapter_12/installing_pip.md">instructions</a> in Chapter 12.
[top](#)
Installing matplotlib on OS X
---
Aple includes matplotlib with its standard Python installation, so make sure you <a href="#checking-if-matplotlib-is-already-installed">check if it's already installed</a> before installing it yourself.
If matplotlib is not already installed and you used Homebrew to install Python, install it like this:
$ pip install --user matplotlib
If you need help using pip, see the <a href="../chapter_12/installing_pip.md">instructions</a> in Chapter 12. If you have trouble installing matplotlib using pip, try leaving off the `--user` flag.
[top](#)
Installing matplotlib on Windows
---
To install matplotlib on Windows you'll first need to install Visual Studio, which will help your system install the packages that matplotlib depends on. Go to [https://dev.windows.com/](https://dev.windows.com/), click [**Downloads**](https://dev.windows.com/downloads), and look for *Visual Studio Community*. This is a free set of developer tools for Windows. Download and run the installer.
Next you'll need an installer for matplotlib. Go to [https://pypi.python.org/pypi/matplotlib/](https://pypi.python.org/pypi/matplotlib/) and look for a wheel file (a file ending in *.whl*) that matches the version of Python you’re using. For example, if you’re using a 32-bit version of Python 3.5, you’ll need to download *matplotlib-1.4.3-cp35-none-win32.whl*.
If you don't see a file matching your installed version of Python, look at what’s available at [http://www.lfd.uci.edu/~gohlke/pythonlibs/#matplotlib](http://www.lfd.uci.edu/~gohlke/pythonlibs/#matplotlib). This site tends to release installers a little earlier than the official matplotlib site.
Copy the *.whl* file to your project folder, open a command window, and navigate to the project folder. Then use pip to install matplotlib:
> cd python_work
python_work> python -m pip install --user matplotlib-1.4.3-cp35-none-win32.whl
If you need help using pip, see the <a href="../chapter_12/installing_pip.md">instructions</a> in Chapter 12.
[top](#)
Installing Pygal
---
Pygal has been updated recently, which is a good thing; you're learning a library that's being steadily improved. This also means you have two choices about how to install Pygal. You can install version 1.7 which supports the code in the book exactly as it's written, or you can install the most recent version of Pygal and modify some of the code in the book. If you install the most recent version there are some slight changes you'll need to make for the code in the second half of chapters 15 and 16, and chapter 17.
### Running Pygal code exactly as it appears in the book
Pygal 1.7 allows the code to run exactly as it appears in the book. To do this, modify the command for installing pygal so pip will install version 1.7 (page 340):
$ pip install --user pygal==1.7
On Windows, this would be:
> python -m pip install --user pygal==1.7
If you've already installed Pygal you can see which version was installed by running the command `pip freeze`:
$ pip freeze
pygal==2.1.1
If you installed Pygal 2.0 or later and want to install 1.7 instead, uninstall Pygal first:
$ pip uninstall pygal
$ pip install --user pygal==1.7
### Using the latest version of Pygal
The latest version of Pygal is version 2.1.1. This is the version that will be installed if you don't specify a version for pip to install:
$ pip install --user pygal
or
$ python -m pip install --user pygal
If you use the latest version, you'll need to make some slight changes to the code in chapter 16 and chapter 17:
- [Updates to Chapter 16 Pygal code](../chapter_16/README.md#updates)
- [Updates to Chapter 17 Pygal code](../chapter_17/README.md#updates)
[top](#)
Updates
---
Pygal has been updated to version 2; make sure you've read the notes about [installing Pygal](#installing-pygal) above.
If you're using Pygal version 2.0 or higher you'll need to add one line to each file in order to render the charts correctly. Pygal has changed the way tooltips are displayed, so if you don't add this line you won't see any tooltips when you hover over the bars on a chart.
Each time you make a chart in Pygal, add a line that tells Pygal to make an SVG file that renders correctly in a browser. For example:
hist = pygal.Bar()
hist.force_uri_protocol = 'http'
This causes Pygal to configure the SVG rendering engine to work correctly for displaying the files in a browser.
Page by page updates
---
Code that appears in bold is new, or is modified from what appears in the book.
### p. 342, die_visual.py
<pre>
hist = pygal.Bar()
<b>hist.force_uri_protocol = 'http'</b>
</pre>
### p. 343-344, dice_visual.py
<pre>
hist = pygal.Bar()
<b>hist.force_uri_protocol = 'http'</b>
</pre>
### p. 345, different_dice.py
<pre>
hist = pygal.Bar()
<b>hist.force_uri_protocol = 'http'</b>
</pre>
没有合适的资源?快使用搜索试试~ 我知道了~
python编程-入门到精通源代码
共335个文件
py:194个
png:59个
html:24个
需积分: 50 45 下载量 81 浏览量
2017-11-02
09:01:14
上传
评论 1
收藏 12.51MB ZIP 举报
温馨提示
非常经典的python入门书籍,里面知识点都用标号标出解释,配套源码可以参考,帮助你更好的学习本书
资源推荐
资源详情
资源评论
收起资源包目录
python编程-入门到精通源代码 (335个子文件)
alien.bmp 10KB
alien.bmp 10KB
ship.bmp 8KB
ship.bmp 8KB
ship.bmp 8KB
ship.bmp 8KB
ship.bmp 8KB
ship.bmp 8KB
sitka_weather_2014.csv 30KB
death_valley_2014.csv 29KB
sitka_weather_07-2014.csv 3KB
.gitignore 49B
.gitignore 31B
.gitignore 13B
base.html 2KB
topic.html 748B
topic.html 578B
login.html 509B
index.html 468B
topics.html 464B
new_topic.html 461B
login.html 442B
base.html 414B
topics.html 391B
topic.html 386B
edit_entry.html 370B
new_entry.html 370B
edit_entry.html 370B
new_entry.html 370B
register.html 339B
register.html 333B
topics.html 322B
new_topic.html 280B
index.html 185B
index.html 185B
base.html 163B
404.html 142B
500.html 135B
population_data.json 1.36MB
population_data.json 1.36MB
numbers.json 20B
installing_pip.md 17KB
README.md 7KB
README.md 7KB
README.md 6KB
windows_setup.md 5KB
README.md 5KB
README.md 4KB
osx_setup.md 4KB
linux_setup.md 3KB
README.md 3KB
README.md 3KB
README.md 2KB
UPDATES.md 1KB
README.md 663B
README.md 225B
beginners_python_cheat_sheet_pcc_all.pdf 1.7MB
beginners_python_cheat_sheet_pcc_django.pdf 636KB
beginners_python_cheat_sheet_pcc_pygal.pdf 561KB
beginners_python_cheat_sheet_pcc_matplotlib.pdf 549KB
beginners_python_cheat_sheet_pcc_pygame.pdf 515KB
beginners_python_cheat_sheet_pcc_classes.pdf 498KB
beginners_python_cheat_sheet_pcc_files_exceptions.pdf 426KB
beginners_python_cheat_sheet_pcc_testing.pdf 401KB
beginners_python_cheat_sheet_pcc_lists.pdf 351KB
beginners_python_cheat_sheet_pcc_if_while.pdf 345KB
beginners_python_cheat_sheet_pcc_dictionaries.pdf 342KB
beginners_python_cheat_sheet_pcc.pdf 328KB
beginners_python_cheat_sheet_pcc_functions.pdf 326KB
crash_course12-02.png 3.81MB
crash_course12-03.png 3.81MB
crash_course15-09.png 279KB
crash_course15-10.png 251KB
crash_course16-09.png 212KB
crash_course12-01.png 207KB
crash_course16-11.png 206KB
crash_course16-10.png 203KB
crash_course15-08.png 169KB
crash_course16-06.png 157KB
crash_course16-08.png 157KB
crash_course16-05.png 155KB
crash_course16-07.png 151KB
crash_course01-02.png 132KB
crash_course16-04.png 131KB
crash_course17-04.png 125KB
crash_course17-02.png 120KB
crash_course15-12.png 108KB
crash_course17-01.png 101KB
crash_course16-03.png 100KB
crash_course01-03.png 99KB
crash_course15-11.png 91KB
crash_course20-03.png 85KB
crash_course15-13.png 78KB
crash_course01-01.png 76KB
crash_course15-06.png 74KB
crash_course15-07.png 73KB
crash_course20-01.png 73KB
crash_course16-02.png 71KB
crash_course18-05.png 63KB
crash_course16-01.png 63KB
共 335 条
- 1
- 2
- 3
- 4
资源评论
caokai_jssz
- 粉丝: 0
- 资源: 1
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功