利用python绘图

import matplotlib.pyplot as plt
import seaborn as seaborn
seaborn.set_style('whitegrid')
import numpy as np

#fig = plt.figure()
#ax = plt.axes()

x = np.linspace(0, 10, 1000)
#ax.plot(x, np.sin(x))

plt.plot(x, np.sin(x),color='blue')
plt.plot(x, np.cos(x))

fig = plt.figure()
plt.plot(x, np.sin(x - 0), color= 'blue' )        # 通过颜色名称指定
plt.plot(x, np.sin(x - 1), color= 'g' )           # 通过颜色简写名称指定(rgbcmyk)
plt.plot(x, np.sin(x - 2), color= '0.75' )        # 介于0-1之间的灰阶值
plt.plot(x, np.sin(x - 3), color= '#FFDD44' )     # 16进制的RRGGBB值
plt.plot(x, np.sin(x - 4), color=(1.0,0.2,0.3)) # RGB元组的颜色值,每个值介于0-1
plt.plot(x, np.sin(x - 5), color= 'chartreuse' ); # 能支持所有HTML颜色名称值

fig = plt.figure()
plt.plot(x, x + 0, linestyle= 'solid' )
plt.plot(x, x + 1, linestyle= 'dashed' )
plt.plot(x, x + 2, linestyle= 'dashdot' )   # 虚线
plt.plot(x, x + 3, linestyle= 'dotted' );   # 点线
plt.plot(x, x + 4, linestyle= '-' )  # 实线
plt.plot(x, x + 5, linestyle= '--' ) # 虚线
plt.plot(x, x + 6, linestyle= '-.' ) # 长短点虚线
plt.plot(x, x + 7, linestyle= ':' );  # 点线

# 调整坐标范围
fig = plt.figure()
plt.plot(x, np.sin(x))
plt.xlim(-1, 11)
plt.ylim(-1.5, 1.5);

# 坐标轴反向
fig = plt.figure()
plt.plot(x, np.sin(x))
plt.xlim(10, 0)
plt.ylim(1.2, -1.2);

# 调整坐标范围2
fig = plt.figure()
plt.plot(x, np.sin(x))
plt.axis([-1, 11, -1.5, 1.5]);

fig = plt.figure()
plt.plot(x, np.sin(x))
plt.axis( 'tight' );

# 通过设置 equal 参数设置x轴与y轴使用相同的长度单位
fig = plt.figure()
plt.plot(x, np.sin(x))
plt.axis( 'equal' );

# 轴标签
fig = plt.figure()
plt.plot(x, np.sin(x))
plt.title("A Sine Curve")
plt.xlabel("x")
plt.ylabel("sin(x)");
# 图上标签
plt.plot(x, np.sin(x),  '-g' , label= 'sin(x)' )
plt.plot(x, np.cos(x),  ':b' , label= 'cos(x)' )
plt.axis( 'equal' )
plt.legend();

# 一次性设置所有的属性
fig = plt.figure()
ax = plt.axes()
ax.plot(x, np.sin(x))
ax.set(xlim=(0, 10), ylim=(-2, 2),
       xlabel='x', ylabel='sin(x)',
       title='A Simple Plot');

# 绘制散点图
fig = plt.figure()
x = np.linspace(0, 10, 30)
y = np.sin(x)
plt.plot(x, y,  'o' , color= 'black' );

#
fig = plt.figure()
rng = np.random.RandomState(0)
for marker in [ 'o' ,  '.' ,  ',' ,  'x' ,  '+' ,  'v' ,  '^' ,  '<' ,  '>' ,  's' ,  'd' ]:
    plt.plot(rng.rand(5), rng.rand(5), marker,
             label="marker= {0} ".format(marker))
plt.legend(numpoints=1)
plt.xlim(0, 1.8);

#
fig = plt.figure()
plt.plot(x, y,  '-ok' );

#
fig = plt.figure()
plt.plot(x, y,  '-p' , color= 'gray' ,
         markersize='15', linewidth='4',
         markerfacecolor= 'white' ,
         markeredgecolor= 'gray' ,
         markeredgewidth='2')
plt.ylim(-1.2, 1.2);

x = np.linspace(0, 10, 30)
y = np.sin(x)


#
fig = plt.figure()
plt.scatter(x, y, marker= 'o' );

#
fig = plt.figure()
rng = np.random.RandomState(0)
x = rng.randn(100)
y = rng.randn(100)
colors = rng.rand(100)
sizes = 1000 * rng.rand(100)

plt.scatter(x, y, c=colors, s=sizes, alpha=0.3,
            cmap= 'viridis' )
plt.colorbar();  # 显示颜色对比条

#
fig = plt.figure()
from sklearn.datasets import load_iris
iris = load_iris()
features = iris.data.T

plt.scatter(features[0], features[1], alpha=0.2,
            s=100*features[3], c=iris.target, cmap= 'viridis' )
plt.xlabel(iris.feature_names[0])
plt.ylabel(iris.feature_names[1]);

#
fig = plt.figure()
x = np.linspace(0, 10, 50)
dy = 0.8
y = np.sin(x) + dy * np.random.randn(50)

plt.errorbar(x, y, yerr=dy, fmt= '.k' );

#
fig = plt.figure()
plt.errorbar(x, y, yerr=dy, fmt= 'o' , color= 'black' ,
             ecolor= 'lightgray' , elinewidth=3, capsize=0);




plt.show()

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值