python画布的默认原点_matplotlib中的中心原点

这篇博客介绍了如何在matplotlib中将轴的中心原点设置到指定位置,并添加箭头效果。通过`center_spines`函数实现轴的居中,并在轴的末端添加指向中心的箭头。此外,文章还展示了如何设置网格线、次要刻度和自定义标签。
摘要由CSDN通过智能技术生成

这绝对属于比matplotlib更麻烦的一类,但现在就开始吧。另外,对于基本情况,请查看centering spines demo in the documentation。

你可以用几种不同的方法来实现这一点,但是为了获得最佳的视觉效果,请考虑以下几点。它远不是完美的,但它相当灵活:import matplotlib.pyplot as plt

import matplotlib as mpl

import matplotlib.patheffects

import numpy as np

def center_spines(ax=None, centerx=0, centery=0):

"""Centers the axis spines at on the axis "ax", and

places arrows at the end of the axis spines."""

if ax is None:

ax = plt.gca()

# Set the axis's spines to be centered at the given point

# (Setting all 4 spines so that the tick marks go in both directions)

ax.spines['left'].set_position(('data', centerx))

ax.spines['bottom'].set_position(('data', centery))

ax.spines['right'].set_position(('d

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值