当前位置:首页>开发>正文

如何用python畫出折線圖? python画折线图,麻烦帮忙看看

2023-07-29 21:51:17 互联网 未知 开发

 如何用python畫出折線圖? python画折线图,麻烦帮忙看看

如何用python畫出折線圖?

奇怪,我安装好pythonware.打上import image会出现以下讯息我是用python 2.51 ,这是pythonware没安装成功吗?>>> import imageTraceback (most recent call last):  File "", line 1, in     import imageImportError: No module named image>>>

python画折线图,麻烦帮忙看看

提示是说2017-01-01不能转化为float数据,因为没有你的数据,提供一个简单的例子(两条折线)
import matplotlib.pyplot as plt

x = [1,2,3]
y = [5,7,4]

x2 = [1,2,3]
y2 = [10,14,12]

plt.plot(x, y, label=First Line)
plt.plot(x2, y2, label=Second Line)

plt.xlabel(Plot Number)
plt.ylabel(Important var)
plt.title(Interesting Graph Check it out)
plt.legend()
plt.savefig("test.png")

请问用python做曲线图方便吗?

1、装PIL呀,全称是Python Imaging Library,强大无比呀。2、magick好象也有python的接口,应该也管使。3、matplotlib好象只是matlab的接口,真要用,机子上得装matlab。4、用Tkinter画图,保存成PS格式,再转换

python 图形化 需要什么库

需要Matplotlib库。
还需要下载numpy,dateutil,pytz,pyparsing,cycler,以及setuptools。

可以到这里直接下载对应版本,直接解压到C:Python27Libsite-packages就可以了。
http://www.lfd.uci.edu/~gohlke/pythonlibs/#matplotlib

如何用python绘制各种图形

1.环境
系统:windowspython版本:python3.6.使用的库:matplotlib,numpy
2.numpy库产生随机数几种方法
import numpy as np
numpy.random
rand(d0, d1, ..., dn)    
In [2]: x=np.random.rand(2,5)
In [3]: x
Out[3]:
array([[ 0.84286554,  0.50007593,  0.66500549,  0.97387807,  0.03993009],
[ 0.46391661,  0.50717355,  0.21527461,  0.92692517,  0.2567891 ]])

randn(d0, d1, ..., dn)查询结果为标准正态分布

In [4]: x=np.random.randn(2,5)
In [5]: x
Out[5]:
array([[-0.77195196,  0.26651203, -0.35045793, -0.0210377 ,  0.89749635],
[-0.20229338,  1.44852833, -0.10858996, -1.65034606, -0.39793635]])
randint(low,high,size)    
生成low到high之间(半开区间 [low, high)),size个数据
In [6]: x=np.random.randint(1,8,4)
In [7]: x
Out[7]: array([4, 4, 2, 7])
random_integers(low,high,size)    
生成low到high之间(闭区间 [low, high)),size个数据
In [10]: x=np.random.random_integers(2,10,5)
In [11]: x
Out[11]: array([7, 4, 5, 4, 2])
3.散点图
x x轴
y y轴
s   圆点面积
c   颜色
marker  圆点形状
alpha   圆点透明度                #其他图也类似这种配置
N=50# height=np.random.randint(150,180,20)# weight=np.random.randint(80,150,20)
x=np.random.randn(N)
y=np.random.randn(N)
plt.scatter(x,y,s=50,c=r,marker=o,alpha=0.5)
plt.show()


4.折线图

x=np.linspace(-10000,10000,100) #将-10到10等区间分成100份
y=x**2 x**3 x**plt.plot(x,y)
plt.show()
折线图使用plot函数

5.条形图
N=y=[20,10,30,25,15]
y1=np.random.randint(10,50,5)
x=np.random.randint(10,1000,N)
index=np.arange(N)
plt.bar(left=index,height=y,color=red,width=0.3)
plt.bar(left=index 0.3,height=y1,color=black,width=0.3)
plt.show()


orientation设置横向条形图
N=y=[20,10,30,25,15]
y1=np.random.randint(10,50,5)
x=np.random.randint(10,1000,N)
index=np.arange(N)# plt.bar(left=index,height=y,color=red,width=0.3)# plt.bar(left=index 0.3,height=y1,color=black,width=0.3)#plt.barh() 加了h就是横向的条形图,不用设置orientation
plt.bar(left=0,bottom=index,width=y,color=red,height=0.5,orientation=horizontal)
plt.show()
6.直方图
m1=100
sigma=20
x=m1 sigma*np.random.randn(2000)
plt.hist(x,bins=50,color="green",normed=True)
plt.show()
# #双变量的直方图# #颜色越深频率越高# #研究双变量的联合分布
#双变量的直方图#颜色越深频率越高#研究双变量的联合分布
x=np.random.rand(1000) y=np.random.rand(1000) plt.hist2d(x,y,bins=40)
plt.show()


7.饼状图
#设置x,y轴比例为1:1,从而达到一个正的圆
#labels标签参数,x是对应的数据列表,autopct显示每一个区域占的比例,explode突出显示某一块,shadow阴影
labes=[A,B,C,D]
fracs=[15,30,45,10]
explode=[0,0.1,0.05,0]#设置x,y轴比例为1:1,从而达到一个正的圆
plt.axes(aspect=1)#labels标签参数,x是对应的数据列表,autopct显示每一个区域占的比例,explode突出显示某一块,shadow阴影
plt.pie(x=fracs,labels=labes,autopct="%.0f%%",explode=explode,shadow=True)
plt.show()


8.箱型图
import matplotlib.pyplot as pltimport numpy as npdata=np.random.normal(loc=0,scale=1,size=1000)#sym 点的形状,whis虚线的长度plt.boxplot(data,sym="o",whis=1.5)plt.show()
#sym 点的形状,whis虚线的长度

如何用matplotlib画折线图

两种常用图类型:Line and scatter plots(使用plot()命令), histogram(使用hist()命令)
2.1 折线图&散点图 Line and scatter plots
2.1.1 折线图 Line plots(关联一组x和y值的直线)

import numpy as np

import pylab as pl

x = [1, 2, 3, 4, 5]# Make an array of x values

y = [1, 4, 9, 16, 25]# Make an array of y values for each x value

pl.plot(x, y)# use pylab to plot x and y
pl.show()# show the plot on the screen
图例 Figure legends
pl.legend((plot1, plot2), (’label1, label2’), best’, numpoints=1)
其中第三个参数表示图例放置的位置:best’‘upper right’, ‘upper left’, ‘center’, ‘lower left’, ‘lower right’.
如果在当前figure里plot的时候已经指定了label,如plt.plot(x,z,label=cos(x2)),直接调用plt.legend()就可以了哦。

import numpy as np

import pylab as pl

x1 = [1, 2, 3, 4, 5]# Make x, y arrays for each graph

y1 = [1, 4, 9, 16, 25]

x2 = [1, 2, 4, 6, 8]

y2 = [2, 4, 8, 12, 16]

plot1 = pl.plot(x1, y1, ’r’)# use pylab to plot x and y : Give your plots names
plot2 = pl.plot(x2, y2, ’go’)
pl.title(’Plot of y vs. x’)# give plot a title

pl.xlabel(’x axis’)# make axis labels

pl.ylabel(’y axis’)

pl.xlim(0.0, 9.0)# set axis limits

pl.ylim(0.0, 30.)

pl.legend([plot1, plot2], (’red line’, ’green circles’), ’best’, numpoints=1)# make legend

pl.show()# show the plot on the screen

最新文章