楼主: ReneeBK
2533 10

Matplotlib for Python Developers [推广有奖]

  • 1关注
  • 62粉丝

VIP

已卖:4898份资源

学术权威

14%

还不是VIP/贵宾

-

TA的文库  其他...

R资源总汇

Panel Data Analysis

Experimental Design

威望
1
论坛币
49640 个
通用积分
55.8137
学术水平
370 点
热心指数
273 点
信用等级
335 点
经验
57805 点
帖子
4005
精华
21
在线时间
582 小时
注册时间
2005-5-8
最后登录
2023-11-26

楼主
ReneeBK 发表于 2015-8-29 22:27:14 |AI写论文

+2 论坛币
k人 参与回答

经管之家送您一份

应届毕业生专属福利!

求职就业群
赵安豆老师微信:zhaoandou666

经管之家联合CDA

送您一个全额奖学金名额~ !

感谢您参与论坛问题回答

经管之家送您两个论坛币!

+2 论坛币

  • Matplotlib for Python Developers
  • By: Sandro Tosi

  • Publisher: Packt Publishing

  • Pub. Date: November 9, 2009

  • Print ISBN-13: 978-1-847197-90-0

  • Pages in Print Edition: 308

  • Subscriber Rating: [5 Ratings] Subscriber Reviews




二维码

扫码加我 拉你入群

请注明:姓名-公司-职位

以便审核进群资格,未注明则拒绝

关键词:Developers Matplotlib developer matplot Develop

已有 1 人评分论坛币 学术水平 热心指数 收起 理由
NewOccidental + 1 + 1 + 1 精彩帖子

总评分: 论坛币 + 1  学术水平 + 1  热心指数 + 1   查看全部评分

沙发
ReneeBK 发表于 2015-8-29 22:29:10
  1. Multiline plots

  2. It's fun to plot a line, but it's even more fun when we can plot more than one line on the same figure. This is really easy with Matplotlib as we can simply plot all the lines that we want before calling show(). Have a look at the following code and screenshot:

  3. In [1]: import matplotlib.pyplot as plt
  4. In [2]: x = range(1, 5)
  5. In [3]: plt.plot(x, [xi*1.5 for xi in x])
  6. Out[3]: [<matplotlib.lines.Line2D object at 0x2076ed0>]
  7. In [4]: plt.plot(x, [xi*3.0 for xi in x])
  8. Out[4]: [<matplotlib.lines.Line2D object at 0x1e544d0>]
  9. In [5]: plt.plot(x, [xi/3.0 for xi in x])
  10. Out[5]: [<matplotlib.lines.Line2D object at 0x20864d0>]
  11. In [6]: plt.show()
复制代码

藤椅
ReneeBK 发表于 2015-8-29 22:30:05
  1. A complete example

  2. Let's now group together all that we've seen so far and create a complete example as follows:

  3. In [1]: import matplotlib.pyplot as plt
  4. In [2]: import numpy as np
  5. In [3]: x = np.arange(1, 5)
  6. In [4]: plt.plot(x, x*1.5, label='Normal')
  7. Out[4]: [<matplotlib.lines.Line2D object at 0x2ab5f50>]
  8. In [5]: plt.plot(x, x*3.0, label='Fast')
  9. Out[5]: [<matplotlib.lines.Line2D object at 0x2ac5210>]
  10. In [6]: plt.plot(x, x/3.0, label='Slow')
  11. Out[6]: [<matplotlib.lines.Line2D object at 0x2ac5650>]
  12. In [7]: plt.grid(True)
  13. In [8]: plt.title('Sample Growth of a Measure')
  14. Out[8]: <matplotlib.text.Text object at 0x2aa8890>
  15. In [9]: plt.xlabel('Samples')
  16. Out[9]: <matplotlib.text.Text object at 0x2aa6150>
  17. In [10]: plt.ylabel('Values Measured')
  18. Out[10]: <matplotlib.text.Text object at 0x2aa6d10>
  19. In [11]: plt.legend(loc='upper left')
  20. Out[11]: <matplotlib.legend.Legend object at 0x2ac5c50>
  21. In [12]: plt.show()
复制代码

板凳
ReneeBK 发表于 2015-8-29 22:31:05
  1. Control colors

  2. We've already seen that in a multiline plot, Matplotlib automatically chooses different colors for different lines. We are also free to choose them by ourselves:

  3. In [1]: import matplotlib.pyplot as plt
  4. In [2]: import numpy as np
  5. In [3]: y = np.arange(1, 3)
  6. In [4]: plt.plot(y, 'y');
  7. In [5]: plt.plot(y+1, 'm');
  8. In [6]: plt.plot(y+2, 'c');
  9. In [7]: plt.show()
复制代码

报纸
ReneeBK 发表于 2015-8-29 22:32:01
  1. In [1]: import matplotlib.pyplot as plt
  2. In [2]: x = [5, 3, 7, 2, 4, 1]
  3. In [3]: plt.plot(x);
  4. In [4]: plt.xticks(range(len(x)), ['a', 'b', 'c', 'd', 'e', 'f']);
  5. In [5]: plt.yticks(range(1, 8, 2));
  6. In [6]: plt.show()

  7. In this code snippet, we used xticks() to specify both, locations and labels and yticks() to only show ticks at odd numbered locations.
复制代码

地板
ReneeBK 发表于 2015-8-29 22:32:57

Histogram Charts

  1. In [1]: import matplotlib.pyplot as plt
  2. In [2]: import numpy as np
  3. In [3]: y = np.random.randn(1000)
  4. In [4]: plt.hist(y);
  5. In [5]: plt.show()
复制代码

7
ReneeBK 发表于 2015-8-29 22:45:40
  1. Error bar charts

  2. In experimental sciences, we know that all the measurements that we take lack perfect precision. This leads to repeating the measurements, which results in obtaining a set of values. The expected result is that all those measures group up around the true value that we want to measure.

  3. The representation of this distribution of data values is done by plotting a single data point, (commonly) the mean value of dataset, and an error bar to represent the overall distribution of data. This helps us to get a general idea of how accurate a measurement is (or how far the reported value could be from the error-free value).

  4. Using the errorbar() function, Matplotlib allows us to create such a graph type.

  5. Let's take a look at the next example:

  6. In [1]: import matplotlib.pyplot as plt
  7. In [2]: import numpy as np
  8. In [3]: x = np.arange(0, 4, 0.2)
  9. In [4]: y = np.exp(-x)
  10. In [5]: e1 = 0.1 * np.abs(np.random.randn(len(y)))
  11. In [6]: plt.errorbar(x, y, yerr=e1, fmt='.-');
  12. In [7]: plt.show()
复制代码

8
ReneeBK 发表于 2015-8-29 22:48:23

Bar Charts

  1. Bar charts

  2. Bar charts display rectangular bars (either vertical or horizontal) with their length proportional to the values they represent. They are commonly used to visually compare two or more values.

  3. The bar() function is used to generate bar charts in Matplotlib. The function expects two lists of values: the X coordinates that are the positions of the bar's left margin and the heights of the bars:

  4. In [1]: import matplotlib.pyplot as plt
  5. In [2]: plt.bar([1, 2, 3], [3, 2, 5]);
  6. In [3]: plt.show()
复制代码

9
ReneeBK 发表于 2015-8-29 22:50:18

Pie Charts

  1. Pie charts

  2. Pie charts are circular representations, divided into sectors (also called wedges). The arc length of each sector is proportional to the quantity we're describing. It's an effective way to represent information when we are interested mainly in comparing the wedge against the whole pie, instead of wedges against each other.

  3. Matplotlib provides the pie() function to plot pie charts from an array X. Wedges are created proportionally, so that each value x of array X generates a wedge proportional to x/sum(X).

  4. Please note that if sum(X) is less than 1, then the pie is drawn using X values directly and no normalization is done, resulting in a pie with discontinuity.

  5. Pie charts look best if the figure and axes are in a square format (if not, with the common rectangular figure, they look like ellipses).

  6. In the next example, we are going to plot a simple pie, using the legend keyword argument to give names to the wedges:

  7. In [1]: import matplotlib.pyplot as plt
  8. In [2]: plt.figure(figsize=(3,3));
  9. In [3]: x = [45, 35, 20]
  10. In [4]: labels = ['Cats', 'Dogs', 'Fishes']
  11. In [5]: plt.pie(x, labels=labels);
  12. In [6]: plt.show()
复制代码

10
goldgood88 发表于 2015-8-30 04:41:34
thanks you work

您需要登录后才可以回帖 登录 | 我要注册

本版微信群
加好友,备注jltj
拉您入交流群
GMT+8, 2026-1-9 07:25