第三天 加油
1. Errorbar Subsample 误差条子样本
显示带有少量错误条的全精度数据图
复制代码
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27import numpy as np import matplotlib.pyplot as plt x = np.arange(0.1, 4, 0.1) y1 = np.exp(-1.0 * x) # 计算指数 y2 = np.exp(-0.5 * x) y1err = 0.1 + 0.1 * np.sqrt(x) # 计算平方根 y2err = 0.1 + 0.1 * np.sqrt(x/2) fig, (ax_l, ax_c, ax_r) = plt.subplots(nrows=1, ncols=3, sharey='none', figsize=(12, 6)) ax_l.set_title('all errorbars') ax_l.errorbar(x, y1, yerr=y1err) ax_l.errorbar(x, y2, yerr=y2err) ax_c.set_title('only every 6th errorbar') ax_c.errorbar(x, y1, yerr=y1err, errorevery=6) ax_c.errorbar(x, y2, yerr=y2err, errorevery=6) ax_r.set_title('second series shifted by 3') ax_r.errorbar(x, y1, yerr=y1err, errorevery=(0, 6)) ax_r.errorbar(x, y2, yerr=y2err, errorevery=(3, 6)) fig.suptitle('Errorbar subsampling for better appearance') plt.show()
2. EventCollection Demo
将样点的x,y坐标在x,y轴上标记出来
复制代码
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40import matplotlib.pyplot as plt from matplotlib.collections import EventCollection import numpy as np np.random.seed(19680801) xdata = np.random.random([2, 10]) xdata1 = xdata[0, :] # 切片 xdata2 = xdata[1, :] xdata1.sort() # 排序 xdata2.sort() ydata1 = xdata1 ** 2 ydata2 = 1 - xdata2 ** 3 fig = plt.figure() ax = fig.add_subplot(1, 1, 1) ax.plot(xdata1, ydata1, color='tab:blue') ax.plot(xdata2, ydata2, color='tab:orange') xevents1 = EventCollection(xdata1, color='tab:blue', linelength=0.05) xevents2 = EventCollection(xdata2, color='tab:orange', linelength=0.05) yevents1 = EventCollection(ydata1, color='tab:blue', linelength=0.05, orientation='vertical') # orientation方向 yevents2 = EventCollection(ydata2, color='tab:orange', linelength=0.05, orientation='vertical') ax.add_collection(xevents1) ax.add_collection(xevents2) ax.add_collection(yevents1) ax.add_collection(yevents2) ax.set_xlim([0, 1]) ax.set_ylim([0, 1]) ax.set_title('line plot with data points') plt.show()
3. Eventplot Demo
复制代码
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32import matplotlib.pyplot as plt import numpy as np import matplotlib matplotlib.rcParams['font.size'] = 8.0 np.random.seed(19680801) data1 = np.random.random([6, 50]) colors1 = ['C{}'.format(i) for i in range(6)] lineoffsets1 = np.array([-15, -3, 1, 1.5, 6, 10]) linelengths1 = [5, 2, 1, 1, 3, 1.5] fig, axs = plt.subplots(2, 2) axs[0, 0].eventplot(data1, colors=colors1, lineoffsets=lineoffsets1, linelengths=linelengths1) axs[1, 0].eventplot(data1, colors=colors1, lineoffsets=lineoffsets1, linelengths=linelengths1, orientation='vertical') data2 = np.random.gamma(4, size=[60, 50]) colors2 = 'black' lineoffsets2 = 1 linelengths2 = 1 axs[0, 1].eventplot(data2, colors=colors2, lineoffsets=lineoffsets2, linelengths=linelengths2) axs[1, 1].eventplot(data2, colors=colors2, lineoffsets=lineoffsets2, linelengths=linelengths2, orientation='vertical') plt.show()
4. Filled polygon 填充多边形
复制代码
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45import numpy as np import matplotlib.pyplot as plt def koch_snowflake(order, scale=10): """ Return two lists x, y of point coordinates of the Koch snowflake. Arguments --------- order : int The recursion depth. scale : float The extent of the snowflake (edge length of the base triangle). """ def _koch_snowflake_complex(order): if order == 0: angles = np.array([0, 120, 240]) + 90 return scale / np.sqrt(3) * np.exp(np.deg2rad(angles) * 1j) else: ZR = 0.5 - 0.5j * np.sqrt(3) / 3 p1 = _koch_snowflake_complex(order - 1) # start points p2 = np.roll(p1, shift=-1) # end points dp = p2 - p1 # connection vectors new_points = np.empty(len(p1) * 4, dtype=np.complex128) new_points[::4] = p1 new_points[1::4] = p1 + dp / 3 new_points[2::4] = p1 + dp * ZR new_points[3::4] = p1 + dp / 3 * 2 return new_points points = _koch_snowflake_complex(order) x, y = points.real, points.imag return x, y x, y = koch_snowflake(order=5) plt.figure(figsize=(8, 8)) plt.axis('equal') plt.fill(x, y) plt.show()
最后
以上就是怕孤单斑马最近收集整理的关于小马良看了直呼“专业”,持续学习matplotlib中···day3第三天 加油的全部内容,更多相关小马良看了直呼“专业”,持续学习matplotlib中···day3第三天内容请搜索靠谱客的其他文章。
本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
发表评论 取消回复