matplotlab坐标轴绘制

import matplotlib.pyplot as plt

import numpy as np



def configure_graph_grid(grid_min, grid_max):
    """Set up a square grid axis"""

    # 设置正方形并限制
    plt.axis('square')
    # plt.axis((grid_min, grid_max, grid_min, grid_max))


def set_ticks(axes, min_val, max_val, tick_size=1):
    """Sets the granularity of the boxes.  Default is 1"""
    ticks = [x for x in range(min_val, max_val, tick_size)]
    axes.set_xticks(ticks)
    axes.set_yticks(ticks)

def plot_axes(grid_min, grid_max):
    """Plot x and y axes, x first then y"""
    plt.plot([grid_min, grid_max], [0,0] , color=".3")
    plt.plot([0,0],[grid_min, grid_max],  color=".3")
    plt.grid()


"""
设置成12x12的网格
"""
min_val, max_val = -12, 12
fig, axes = plt.subplots(figsize=(8,8))
configure_graph_grid(min_val, max_val) # 设置网格最小和最大值
plot_axes(min_val, max_val) #
set_ticks(axes, min_val, max_val) # 12 X 12的网格



from math import nan

# 简单微积分函数
def function_with_asympotes(x):
    """Implement a fractional function with a possible zero in the denominator"""
    denom = (x + 3) * (x - 1)
    if denom:
        return x / denom
    else:
        return nan
x_array = np.linspace(-5, 5, 100)
y_array = np.array([function_with_asympotes(x) for x in x_array])


# 一元一次方程
def linear(x, m=2, b=-1):
    """A function to plot an arbitrary point (x) on a line."""
    return m * x + b

x_values = [-5, 5]
y_values = [linear(x) for x in x_values]


plt.plot(x_values, y_values)
line = plt.plot(x_array, y_array)

plt.show()

在这里插入图片描述

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

Ko-walski

太难了,求鼓励

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值