python代码画简单图-Python figure参数及subplot子图绘制代码

1. Python的figure参数主要有:

def figure(num=None, # autoincrement if None, else integer from 1-N

figsize=None, # defaults to rc figure.figsize

dpi=None, # defaults to rc figure.dpi

facecolor=None, # defaults to rc figure.facecolor

edgecolor=None, # defaults to rc figure.edgecolor

frameon=True,

FigureClass=Figure,

clear=False,

**kwargs

):

可以设置图片大小、分辨率、颜色等。

2. subplot子图绘制,子图的绘图参数可以分别设置

plt.figure(1)

x1 = np.linspace(-0.2, 2, 10)

y1 = x1**2 + 0.3

plt.subplot(121)

plt.scatter(x1, y1)

plt.xlabel('X')

plt.ylabel('Y')

plt.title('test_1')

x2 = np.linspace(-0.2, 2, 10)

y2 = x2 + 0.3

plt.subplot(122)

plt.plot(x2, y2, color="red", linewidth=1.0, marker = 's', linestyle="--")

## plt.plot(x, y, color="#ef5492", linewidth=2.0, marker = 's', linestyle="--")

# plt.plot(x2, y2, 'rs--')

plt.xlabel('X')

plt.ylabel('Y')

plt.title('test_2')

plt.show()

2020041811151519.png

3. 在同一张图片上显示多种图形,简单说把 plt.show()放在最后即可

import matplotlib.pyplot as plt

import numpy as np

plt.figure(2)

x1 = np.linspace(-0.2, 2, 10)

y1 = x1**2 + 0.3

plt.scatter(x1, y1)

x2 = np.linspace(-0.2, 2, 10)

y2 = x2 + 0.3

plt.plot(x2, y2, color="red", linewidth=1.0, marker = 's', linestyle="--")

## plt.plot(x, y, color="#ef5492", linewidth=2.0, marker = 's', linestyle="--")

# plt.plot(x2, y2, 'rs--')

plt.xlabel('X')

plt.ylabel('Y')

plt.title('test_3')

plt.show()

2020041811151520.png

以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持脚本之家。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值