Matplotlib--axis坐标轴

import matplotlib.pyplot as plt
import numpy as np
from scipy.stats import norm,t

plt.rcParams['font.family'] = ["SimHei"]
plt.rcParams['axes.unicode_minus']=False
x = np.linspace(-5,10,100)
y1 = norm.pdf(x, loc=0, scale=1)
y2 = t.pdf(x, df=1)

设置刻度范围与样式

plt.figure()

plt.plot(x, y1)
plt.plot(x, y2, linestyle='--')

# 设置坐标轴范围
plt.xlim((-5,5))
plt.ylim((-0.5,0.5))
# 设置坐标轴刻度
plt.xticks(ticks=np.arange(-5,6,2),labels=['负五','负三','负一','一','三','五'],
           rotation=15, size=20)
plt.yticks(ticks=[-0.1,0.5])

plt.show()

在这里插入图片描述

fig = plt.figure()
ax = fig.add_subplot()

plt.plot(x, y1)
plt.plot(x, y2, linestyle='--')

ax.spines['top'].set_color('red')
ax.spines['right'].set_color('none')
# 设置坐标轴刻度位置
ax.xaxis.set_ticks_position('top')
ax.yaxis.set_ticks_position('right')

ax.spines['left'].set_position(('data',0))
ax.spines['bottom'].set_position(('data',0.1))

设置坐标轴位置

在这里插入图片描述

添加新ax

fig, ax = plt.subplots()

plt.plot(x, y1)
plt.plot(x, y2, linestyle='--')

ax_1 = ax.twinx()
ax_1.set_ylim(0,20)
ax_1.spines['right'].set_position(('data',3))

ax_2 = ax.twiny()
ax_2.set_xlim(-25,25)
ax_2.spines['top'].set_position(('data',0.2))

ax.set_xlim(-5,5)
# 这两行失效了???
ax.spines['top'].set_color('none')
ax.spines['right'].set_color('none')

在这里插入图片描述

  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值