属性

*)在使用animate方法中若让interval=0,则会直接输出最后一帧

*)清除图像  包括这个方法到底是图形区的对象调用的还是画布对象调用的?

  这个莫名其妙就起作用了

  来源连接:https://codeday.me/bug/20170309/5150.html

def update_insert(i):
global ax,X
plt.cla()#要以绘图区的对象调用的方法吧
# plt.close()#这里又能关闭了
# plt.clf()#清楚figure里的内容
X=np.random.randint(0,100,10)
ax.scatter(X,X)
plt.xticks([]),plt.yticks([])
return ax,X

 

 *)调整图像边缘及图像间的空白间隔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 plt
from 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 plt
from 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()

  

错误

*)c:\users\administrator.sc-201605202132\appdata\local\programs\python\python36\Lib\tkinter\__init__.py:1705: UserWarning: Tight layout not applied. The left and right margins cannot be made large enough to accommodate all axes decorations.

axs=fig.add_subplot(111)
axs.set_xlim(0,7)
axs.set_ylim(0,5)
text= axs.text(0.02,0.90,'test',transform=axs.transAxes)
text.set_backgroundcolor('r')
text.set_position((0.9,.9))#不能超过1,和上面的设置是一样的

  

*)matplotlib.units.ConversionError: Failed to convert value(s) to axis units: ['bubble_sort', 'bidirectional_bubble_sort']

xticks=[d.__name__ for d in algorithm_list]
print(xticks)
axs.set_xticks(xticks)#因为是字符串数组,所以不能,应该是数字
#xticks
['bubble_sort', 'bidirectional_bubble_sort']

  

*)ValueError: The truth value of an array with more than one element is ambiguous. Use a.any() or a.all()

#错误的
spend_time=[1,2]
axs.set_yticks([spend_time])
#True
axs.set_yticks(spend_time)

  

*)axs[i].set_xticks([])   TypeError: 'list' object is not callable


参考链接:https://stackoverflow.com/questions/46231439/problems-with-matplotlib-pyplot-xticks(见回答2)

  原因:是因为起那面已经有过设置x轴标记为空的了

for i in range(algorithm_num):
frames_names[algorithm_list[i].__name__]=[]
#顺便对画布进行设置
axs.append(fig.add_subplot(121+i))
# axs[-1].set_xticks=([])#这里已经有过了,将这个注释掉
# axs[-1].set_yticks=([])
#顺便运行函数了
frames_names[algorithm_list[i].__name__]=algorithm_list[i](copy.deepcopy(original_data_object))
plt.subplots_adjust(left=0.05,right=0.95,bottom=0.1,top=0.90,wspace=0.1,hspace=0.2) #寻找最大帧,算了,还是把所有的帧数都存到一个dict里面吧,但是dict好像不能向里面添加
frame_count={}
for i in range(algorithm_num):
frame_count['{}'.format(algorithm_list[i])]=str(len(frames_names[algorithm_list[i].__name__]))
def animate(fi):
bars=[]
for i in range(algorithm_num):
if len(frames_names[algorithm_list[i].__name__])>fi:
axs[i].cla() axs[i].set_xticks([])
axs[i].set_yticks([])
axs[i].set_title(str(algorithm_list[i].__name__))
bars+=axs[i].bar(list(range(Data.data_count)),
[d.value for d in frames_names[algorithm_list[i].__name__][fi]],
1,
color=[d.color for d in frames_names[algorithm_list[i].__name__][fi]],
).get_children()
return bars

  

*)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“当前”形状的下一个颜色确定并填充“颜色循环”。此周期默认为rcParams["axes.prop_cycle"]

        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

  *)ValueError: shape mismatch: objects cannot be broadcast to a single shape错误:

  可能是因为传入的两个参数之间不是一一对应的,类似于因为长度的原因,一个参数中的某些数据不能和另一个参数中的数据一起被使用。比如在画图的时候

bars+=ax.bar(list(range(0,Data.data_count)),#我在创建数据的时候搞错了,这里是16个,而下面的是17个
[d.value for d in frames[fi]],
1,
color=[d.color for d in frames[fi]]
).get_children()

  *)类中的类似变量名错误的错误不会提示啊,哦哦好像是别的地方就写错了

def set_color(self,ragb=None):#这里也写错了
if not ragb:#这里也写错了
rgba=(0,#但是这个这么没有提示
1-self.value/(self.data_count*2),
self.value/(self.data_count*2)+0.5,
1)
self.color=ragb
---snip---
d=Data(2)
print(d.color) #输出
(sort) λ python Visualization_bubble_sort.py
None

  

  

Matplotlib 绘图与可视化 一些属性和错误的更多相关文章

  1. Matplotlib 绘图与可视化 一些控件的介绍和属性,反正就是乱七八糟的

    这个链接里有下面这个图(图里还有超链接):https://matplotlib.org/3.1.1/api/artist_api.html#matplotlib.artist.Artist 各种图例: ...

  2. python金融与量化分析------Matplotlib(绘图和可视化)

    -----------------------------------------------------------Matplotlib:绘图和可视化------------------------ ...

  3. Py修行路 Matplotlib 绘图及可视化模块

    Matplotlib是一个强大的Python绘图和数据可视化的工具包. 安装方法:pip install matplotlib 引用方法:import matplotlib.pyplot as plt ...

  4. matplotlib绘图基本用法-转自(http://blog.csdn.net/mao19931004/article/details/51915016)

    本文转载自http://blog.csdn.net/mao19931004/article/details/51915016 <!DOCTYPE html PUBLIC "-//W3C ...

  5. python实战学习之matplotlib绘图续

    学习完matplotlib绘图可以设置的属性,还需要学习一下除了折线图以外其他类型的图如直方图,条形图,散点图等,matplotlib还支持更多的图,具体细节可以参考官方文档:https://matp ...

  6. python中利用matplotlib绘图可视化知识归纳

    python中利用matplotlib绘图可视化知识归纳: (1)matplotlib图标正常显示中文 import matplotlib.pyplot as plt plt.rcParams['fo ...

  7. Matplotlib:绘图和可视化

    Matplotlib:绘图和可视化 简介 简单绘制线形图 plot函数 支持图类型 保存图表 一 .简介 Matplotlib是一个强大的Python绘图和数据可视化的工具包.数据可视化也是我们数据分 ...

  8. 基于matplotlib的数据可视化 - 笔记

    1 基本绘图 在plot()函数中只有x,y两个量时. import numpy as np import matplotlib.pyplot as plt # 生成曲线上各个点的x,y坐标,然后用一 ...

  9. Python 数据分析(一) 本实验将学习 pandas 基础,数据加载、存储与文件格式,数据规整化,绘图和可视化的知识

    第1节 pandas 回顾 第2节 读写文本格式的数据 第3节 使用 HTML 和 Web API 第4节 使用数据库 第5节 合并数据集 第6节 重塑和轴向旋转 第7节 数据转换 第8节 字符串操作 ...

随机推荐

  1. 关于错误CSC : error CS0006:未能找到元数据文件

    在不同的解决方案中把一个项目搬来搬去,终于出现了传说的CSC : error CS0006.编译的时候总是提示一个引用中不存在的项找不到.无论怎样删除项目,删除引用都没法通过生成. 最终解决方案: 用 ...

  2. SSH框架整合截图总结(三)

    联系人信息查询1 点击 联系人信息查询 超链接时候,到查询页面 (1)在查询页面中,选择客户,根据客户进行查询 下拉表框显示所有客户  可以根据所属的客户进行联系人查询  2 在查询页面中,输入值,提 ...

  3. botot framework选择下拉框

    1,下拉框不能输入文字,如图: 方法: select from list    id=xxx   要选择的数据 2.下拉框可输入文字,如图: 方法: click element   di=xxx   ...

  4. LCA【模板】

    #include <algorithm> #include <cstdio> #include <vector> #define N 10015 using nam ...

  5. linux 下 The valid characters are defined in RFC 7230 and RFC 3986

    换tomcat 8.0.38就ok . 下载地址: http://archive.apache.org/dist/tomcat/tomcat-8/v8.0.38/bin/apache-tomcat-8 ...

  6. HDU 3003

    找规律吧.可以快速幂模 #include <iostream> #include <cstdio> using namespace std; __int64 Power(__i ...

  7. JMX学习笔记(一)-MBean

    JMX学习笔记(一)-MBean 标签: jmxstringjavainterfaceexceptionclass 2010-12-07 22:20 15360人阅读 评论(5) 收藏 举报  分类: ...

  8. Oracle 单表选择率

    听了猫大师的课,对Oracle CBO又加深了一步理解: 单表选择率: selectivity=1/ndv*a4nulls ocard来自dba_tables.num_rows ndv 来自dba_t ...

  9. UVA 11426 - GCD - Extreme (II) 欧拉函数-数学

    Given the value of N, you will have to find the value of G. The definition of G is given below:G =i< ...

  10. linux删除多行

    光标放到行dd:删除所在行 光标放到行Ndd: 删除所在行下的N行