博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
Matplotlib 绘图与可视化 一些属性和错误
阅读量:7087 次
发布时间:2019-06-28

本文共 3051 字,大约阅读时间需要 10 分钟。

属性

  *)调整图像边缘及图像间的空白间隔plt.subplots.adjust(6个参数)

  图像外部边缘的调整可以使用plt.tight_layout()进行自动控制,此方法不能够很好的控制图像间的间隔.如果想同时控制图像外侧边缘以及图像间的空白区域,使用命令:

plt.subplots_adjust(left=0.2, bottom=0.2, right=0.8, top=0.8,hspace=0.2, wspace=0.3)

  *)subplot(111)参数为111,即中间没有逗号隔开的意思。

  参考链接:https://blog.csdn.net/S201402023/article/details/51536687

  

#引入对应的库函数import matplotlib.pyplot as pltfrom numpy import *#绘图fig = plt.figure()ax = fig.add_subplot(349)ax.plot(x,y)plt.show()

  其中,参数349的意思是:将画布分割成3行4列,图像画在从左到右从上到下的第9块

  那第十块怎么办,3410是不行的,可以用另一种方式(3,4,10)。

  如果一块画布中要显示多个图怎么处理?

import matplotlib.pyplot as pltfrom numpy import *fig = plt.figure()ax = fig.add_subplot(2,1,1)ax.plot(x,y)ax = fig.add_subplot(2,2,3)ax.plot(x,y)plt.show()

  

错误

*)funcAnimation()中frags向帧函数传递附加参数时格式不对提示错误TypeError: update_insert() takes 2 positional arguments but 10 were given

正确格式:

anim=animation.FuncAnimation(plt.fig,update_insert,init_func=None,repeat=False,frames=np.arange(0,6 ),interval=2000,fargs=(collection))def update_insert(i,*collection):    global ax,X    print(collection)     --snip--

  

*)由于scatter()中参数不规范引起的错误

参考链接:https://matplotlib.org/3.1.0/api/_as_gen/matplotlib.pyplot.scatter.html?highlight=scatter#matplotlib.pyplot.scatter

标记颜色。可能的值:

  • 单色格式字符串。
  • 一系列长度为n的颜色规格。
  • 使用cmap和 norm映射到颜色的n个数字序列。
  • 一个二维数组,其中行是RGB或RGBA。

请注意,c不应该是单个数字RGB或RGBA序列,因为它与要进行颜色映射的值数组无法区分。如果要为所有点指定相同的RGB或RGBA值,请使用具有单行的二维数组。否则,在大小与x 和y匹配的情况下,值匹配将具有优先权。

默认为None。在这种情况下,标记的颜色是由的值来确定colorfacecolorfacecolors。如果未指定或None标记颜色,则标记颜色由Axes“当前”形状的下一个颜色确定并填充“颜色循环”。此周期默认为

ax.scatter(X1,X1,c=b)        ax.scatter(X2,X2,c=b,s=50)        ax.scatter(X1,X1,c=g)

  会报错:

(sort) λ python matplotlib_learn.py[1, 2, 3, 4, 5]Traceback (most recent call last):  File "C:\Users\Administrator.SC-201605202132\Envs\sort\lib\site-packages\matplotlib\cbook\__init__.py", line 216, in process    func(*args, **kwargs)  File "C:\Users\Administrator.SC-201605202132\Envs\sort\lib\site-packages\matplotlib\animation.py", line 953, in _start    self._init_draw()  File "C:\Users\Administrator.SC-201605202132\Envs\sort\lib\site-packages\matplotlib\animation.py", line 1732, in _init_draw    self._draw_frame(next(self.new_frame_seq()))  File "C:\Users\Administrator.SC-201605202132\Envs\sort\lib\site-packages\matplotlib\animation.py", line 1755, in _draw_frame    self._drawn_artists = self._func(framedata, *self._args)  File "matplotlib_learn.py", line 184, in update_insert    ax.scatter(X2,X2,c=b,s=50)  File "C:\Users\Administrator.SC-201605202132\Envs\sort\lib\site-packages\matplotlib\__init__.py", line 1589, in inner    return func(ax, *map(sanitize_sequence, args), **kwargs)  File "C:\Users\Administrator.SC-201605202132\Envs\sort\lib\site-packages\matplotlib\axes\_axes.py", line 4446, in scatter    get_next_color_func=self._get_patches_for_fill.get_next_color)  File "C:\Users\Administrator.SC-201605202132\Envs\sort\lib\site-packages\matplotlib\axes\_axes.py", line 4257, in _parse_scatter_color_args    n_elem = c_array.shape[0]IndexError: tuple index out of range

  

转载于:https://www.cnblogs.com/Gaoqiking/p/11075384.html

你可能感兴趣的文章
101 Symmetric Tree
查看>>
GIT命令速查
查看>>
ThinkPHP控制器学习(二)
查看>>
css_01 | CSS——CSS 基础与选择器初识
查看>>
一文看懂 Kafka 消息格式的演变
查看>>
居然有人能忘记吃饭?写个微信机器人提醒他
查看>>
你需要知道的算法之基础篇
查看>>
一些基础css图形的实现
查看>>
Hadoop学习笔记(1)
查看>>
D2 日报 2019年5月19日
查看>>
浅谈async/await
查看>>
Flutter杂症( flutter packages pub run build_runner build )
查看>>
LeetCode集锦(二) - reverse integer
查看>>
Java开发者职业生涯要看的200+本书
查看>>
JavaScript 中的 JSON
查看>>
DDD与面向对象设计
查看>>
Remove.bg 免費圖片去背線上工具,5 秒輕鬆幫人物去背景,連我阿嬤都會去背!- TechMoon 科技月球...
查看>>
JavaScript基础知识-(对象)
查看>>
tail: 输出文件的末尾部分
查看>>
小猿圈web前端开发面试需要注意哪些?
查看>>