- ubuntu12.04环境下使用kvm ioctl接口实现最简单的虚拟机
- Ubuntu 通过无线网络安装Ubuntu Server启动系统后连接无线网络的方法
- 在Ubuntu上搭建网桥的方法
- ubuntu 虚拟机上网方式及相关配置详解
CFSDN坚持开源创造价值,我们致力于搭建一个资源共享平台,让每一个IT人在这里找到属于你的精彩世界.
这篇CFSDN的博客文章Python使用matplotlib和pandas实现的画图操作【经典示例】由作者收集整理,如果你对这篇文章有兴趣,记得点赞哟.
本文实例讲述了Python使用matplotlib和pandas实现的画图操作。分享给大家供大家参考,具体如下:
画图在工作再所难免,尤其在做数据探索时候,下面总结了一些关于python画图的例子 。
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
|
#encoding:utf-8
'''''
Created on 2015年9月11日
@author: ZHOUMEIXU204
'''
# pylab 是 matplotlib 面向对象绘图库的一个接口。它的语法和 Matlab 十分相近
import
pandas as pd
#from ggplot import *
import
numpy as np
import
matplotlib.pyplot as plt
df
=
pd.DataFrame(np.random.randn(
1000
,
4
),columns
=
list
(
'ABCD'
))
df
=
df.cumsum()
print
(plt.figure())
print
(df.plot())
print
(plt.show())
# print(ggplot(df,aes(x='A',y='B'))+geom_point())
|
运行效果:
1
2
3
4
5
6
7
|
# 画简单的图形
from
pylab
import
*
x
=
np.linspace(
-
np.pi,np.pi,
256
,endpoint
=
True
)
c,s
=
np.cos(x),np.sin(x)
plot(x,c, color
=
"blue"
, linewidth
=
2.5
, linestyle
=
"-"
, label
=
"cosine"
)
#label用于标签显示问题
plot(x,s,color
=
"red"
, linewidth
=
2.5
, linestyle
=
"-"
, label
=
"sine"
)
show()
|
运行效果:
1
2
3
4
5
6
7
|
#散点图
from
pylab
import
*
n
=
1024
X
=
np.random.normal(
0
,
1
,n)
Y
=
np.random.normal(
0
,
1
,n)
scatter(X,Y)
show()
|
运行效果:
1
2
3
4
5
6
7
8
9
10
11
12
|
#条形图
from
pylab
import
*
n
=
12
X
=
np.arange(n)
Y1
=
(
1
-
X
/
float
(n))
*
np.random.uniform(
0.5
,
1.0
,n)
Y2
=
(
1
-
X
/
float
(n))
*
np.random.uniform(
0.5
,
1.0
,n)
bar(X,
+
Y1, facecolor
=
'#9999ff'
, edgecolor
=
'white'
)
bar(X,
-
Y2, facecolor
=
'#ff9999'
, edgecolor
=
'white'
)
for
x,y
in
zip
(X,Y1):
text(x
+
0.4
, y
+
0.05
,
'%.2f'
%
y, ha
=
'center'
, va
=
'bottom'
)
ylim(
-
1.25
,
+
1.25
)
show()
|
运行效果:
1
2
3
4
5
|
#饼图
from
pylab
import
*
n
=
20
Z
=
np.random.uniform(
0
,
1
,n)
pie(Z), show()
|
运行效果:
1
2
3
4
5
6
7
8
9
10
11
12
13
|
#画三维图
import
numpy as np
from
mpl_toolkits.mplot3d
import
Axes3D
from
pylab
import
*
fig
=
figure()
ax
=
Axes3D(fig)
x
=
np.arange(
-
4
,
4
,
0.1
)
y
=
np.arange(
-
4
,
4
,
0.1
)
x,y
=
np.meshgrid(x,y)
R
=
np.sqrt(x
*
*
2
+
y
*
*
2
)
z
=
np.sin(R)
ax.plot_surface(x,y,z,rstride
=
1
,cstride
=
1
,cmap
=
'hot'
)
show()
|
运行效果:
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
|
#用于图像显示的问题
import
matplotlib.pyplot as plt
import
pandas as pd
weights_dataframe
=
pd.DataFrame()
plt.figure()
plt.plot(weights_dataframe.weights_ij,weights_dataframe.weights_x1,label
=
'weights_x1'
)
plt.plot(weights_dataframe.weights_ij,weights_dataframe.weights_x0,label
=
'weights_x0'
)
plt.plot(weights_dataframe.weights_ij,weights_dataframe.weights_x2,label
=
'weights_x2'
)
plt.legend(loc
=
'upper right'
)
#用于标签显示问题
plt.xlabel(u
"迭代次数"
, fontproperties
=
'SimHei'
)
plt.ylabel(u
"参数变化"
, fontproperties
=
'SimHei'
)
plt.title(u
"迭代次数显示"
, fontproperties
=
'SimHei'
)
#fontproperties='SimHei' 用于可以显示中文
plt.show()
import
matplotlib.pyplot as plt
from
numpy.random
import
random
colors
=
[
'b'
,
'c'
,
'y'
,
'm'
,
'r'
]
lo
=
plt.scatter(random(
10
), random(
10
), marker
=
'x'
, color
=
colors[
0
])
ll
=
plt.scatter(random(
10
), random(
10
), marker
=
'o'
, color
=
colors[
0
])
l
=
plt.scatter(random(
10
), random(
10
), marker
=
'o'
, color
=
colors[
1
])
a
=
plt.scatter(random(
10
), random(
10
), marker
=
'o'
, color
=
colors[
2
])
h
=
plt.scatter(random(
10
), random(
10
), marker
=
'o'
, color
=
colors[
3
])
hh
=
plt.scatter(random(
10
), random(
10
), marker
=
'o'
, color
=
colors[
4
])
ho
=
plt.scatter(random(
10
), random(
10
), marker
=
'x'
, color
=
colors[
4
])
plt.legend((lo, ll, l, a, h, hh, ho),
(
'Low Outlier'
,
'LoLo'
,
'Lo'
,
'Average'
,
'Hi'
,
'HiHi'
,
'High Outlier'
),
scatterpoints
=
1
,
loc
=
'lower left'
,
ncol
=
3
,
fontsize
=
8
)
plt.show()
|
1
2
3
4
5
6
7
8
9
10
11
12
13
|
#pandas中画图
#画累和图
import
pandas as pd
import
numpy as np
import
matplotlib.pyplot as plt
ts
=
pd.Series(np.random.randn(
1000
),index
=
pd.date_range(
'1/1/2000'
,periods
=
1000
))
ts
=
ts.cumsum()
ts.plot()
plt.show()
df
=
pd.DataFrame(np.random.randn(
1000
,
4
),index
=
ts.index,columns
=
list
(
'ABCD'
))
df
=
df.cumsum()
df.plot()
plt.show()
|
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
|
import
pandas as pd
import
numpy as np
import
matplotlib.pyplot as plt
#画柱状图
df2
=
pd.DataFrame(np.random.rand(
10
,
4
), columns
=
[
'a'
,
'b'
,
'c'
,
'd'
])
df2.plot(kind
=
'bar'
)
#分开并列线束
df2.plot(kind
=
'bar'
, stacked
=
True
)
#四个在同一个里面显示 百分比的形式
df2.plot(kind
=
'barh'
, stacked
=
True
)
#纵向显示
plt.show()
df4
=
pd.DataFrame({
'a'
:np.random.randn(
1000
)
+
1
,
'b'
:np.random.randn(
1000
),
'c'
:np.random.randn(
1000
)
-
1
},columns
=
list
(
'abc'
))
df4.plot(kind
=
'hist'
, alpha
=
0.5
)
df4.plot(kind
=
'hist'
, stacked
=
True
, bins
=
20
)
df4[
'a'
].plot(kind
=
'hist'
, orientation
=
'horizontal'
,cumulative
=
True
)
#cumulative是按顺序排序,加上这个
plt.show()
#Area Plot
df
=
pd.DataFrame(np.random.rand(
10
,
4
), columns
=
[
'a'
,
'b'
,
'c'
,
'd'
])
df.plot(kind
=
'area'
)
df.plot(kind
=
'area'
,stacked
=
False
)
plt.show()
|
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
|
#散点图
import
pandas as pd
import
numpy as np
import
matplotlib.pyplot as plt
df
=
pd.DataFrame(np.random.rand(
50
,
4
), columns
=
[
'a'
,
'b'
,
'c'
,
'd'
])
df.plot(kind
=
'scatter'
, x
=
'a'
, y
=
'b'
)
df.plot(kind
=
'scatter'
, x
=
'a'
, y
=
'b'
,color
=
'DarkBlue'
, label
=
'Group 1'
)
#饼图
df
=
pd.DataFrame(
3
*
np.random.rand(
4
,
2
), index
=
[
'a'
,
'b'
,
'c'
,
'd'
], columns
=
[
'x'
,
'y'
])
df.plot(kind
=
'pie'
, subplots
=
True
, figsize
=
(
8
,
4
))
df.plot(kind
=
'pie'
, subplots
=
True
,autopct
=
'%.2f'
,figsize
=
(
8
,
4
))
#显示百分比
plt.show()
#画矩阵散点图
df
=
pd.DataFrame(np.random.randn(
1000
,
4
), columns
=
[
'a'
,
'b'
,
'c'
,
'd'
])
pd.scatter_matrix(df, alpha
=
0.2
, figsize
=
(
6
,
6
), diagonal
=
'kde'
)
plt.show()
|
实际我个人喜欢用R语言画图,python画图也有ggplot类似的包 。
希望本文所述对大家Python程序设计有所帮助.
原文链接:https://blog.csdn.net/luoyexuge/article/details/49069225 。
最后此篇关于Python使用matplotlib和pandas实现的画图操作【经典示例】的文章就讲到这里了,如果你想了解更多关于Python使用matplotlib和pandas实现的画图操作【经典示例】的内容请搜索CFSDN的文章或继续浏览相关文章,希望大家以后支持我的博客! 。
本文实例总结了常用SQL语句优化技巧。分享给大家供大家参考,具体如下: 除了建立索引之外,保持良好的SQL语句编写习惯将会降低SQL性能问题发生。 ①通过变量的方式来设置参数 好:
写CSS的同学们往往会体会到,随着项目规模的增加,项目中的CSS代码也会越来越多,如果没有及时对CSS代码进行维护,CSS代码不断会越来越多。CSS代码交错复杂,像一张庞大的蜘蛛网分布在网站的各个位
所以我必须解决类的背包问题。到目前为止,我想出了以下内容。我的比较器是确定两个主题中哪一个是更好选择的函数(通过查看相应的(值,工作)元组)。 我决定迭代工作量小于 maxWork 的可能主题,并且为
前言:复杂类型说明 要了解指针,多多少少会出现一些比较复杂的类型,所以我先介绍一下如何完全理解一个复杂类型,要理解复杂类型其实很简单,一个类型里会出现很多运算符,他们也像普通的表达式一样,有优先级
代码如下: 复制代码代码如下: USE [tempdb] GO /****** Object: UserDefinedFunction [dbo].[fun
最近收到一个工作要求,让我完成一个每天一次的Linux服务器巡检工作(服务器的版本为红帽6.4),不可以使用监控软件来操作。在这里,把我的巡检过程和巡检脚本放送给大家做一参考。 首先,巡检内容
可以在 Classic ASP 中动态创建“空”对象并创建对象属性吗? 以这个 JavaScript 示例为例: var sample = new Object(); sample.prop = "O
我正在向旧的经典 asp 站点添加功能,但遇到了一个有趣的问题。页面上的以下行导致有用的错误“需要对象:''” strServerName = Request.ServerVariables("ser
我有一个经典的 ASP 应用程序,我正在处理日期截止。我的服务器位于中部时间,但我在东部时间。发生的情况是我的应用程序认为它早了一个小时,而我的截止时间晚了一个小时。我敢肯定,如果用户在太平洋时间,他
我是经典 ASP 的初学者。需要拆分一个由逗号分隔的许多电子邮件组成的字符串,并使用稍后生成的附加代码将结果插入(逐个电子邮件)到表格中。每条记录都应该有一个电子邮件地址。问题是我陷入了数组范围错误。
这个问题已经有答案了: one condition, multiple events (2 个回答) 已关闭 6 年前。 如何用更小的语句替换 1,2,3..。我尝试将 1 放入 10,但显示错误。
我是 ExtJS 的新手,所以我不知道是否可能。 Google 只回答如何为图表制作工具提示,所以... 我需要制作一个带有工具提示的网格,当用户将鼠标放在单元格上时将显示该工具提示。在该工具提示中,
我正在使用一个非常奇怪的 VB 版本...它不需要我告诉它什么是什么,它想自己弄清楚。 在 C# 中,我可以轻松地对数组进行硬编码...在 VB 中则不然。 我想在调用函数时创建一个硬编码数组...但
我的数据库访问代码如下: set recordset = Server.CReateObject("ADODB.Recordset") set cmd1 = Server.CreateObject(
我有 html 按钮和文本框的代码:文本框是我输入文本的地方,以便我可以在表格上进行一些更改。 'textbox " /> 'button Clear 我现在需要做的是单击“清除”按
我有一个表单,提交后会通过电子邮件发送。该表单使用 JavaScript 进行验证。经典 ASP 处理表单,即获取输入的数据、创建然后发送电子邮件。有报道称正在提交空白表格。仅发送标题和 Logo 。
加载页面 A.asp 默认情况下正在执行,从那里开始执行电子邮件的情况,如果是电子邮件,我们将调用页面 B。我想在控件被执行时执行相同的电子邮件情况从页面 B 转移到页面 A。请帮助我。 Page A
我正在使用经典 ASP 开发一个项目,例如,我想添加一些用户作为临时列表,当我提交表单时,这些数据将保存到数据库中。 我知道如何在 asp.net 中使用它,但不知道如何在经典 asp 中使用它。 例
我有一个带有简单 html 表的经典 ASP 页面,我想根据从数据库中提取的未知数量的记录循环表行,但是,当我使用 do/while 循环循环记录时,我收到一条错误消息,指出 Either BOF o
嘿,一直在寻找一段时间,但我似乎找不到任何有关如何在经典 asp 中处理日期的信息。 现在,我需要一种方法来计算今年过去的天数。我正在考虑一个简单的函数,它将获取当前日期,然后使用 (day = 1,
我是一名优秀的程序员,十分优秀!