我想用meshgrid绘制多个大小为1x1的正方形.给出了电流和预期输出.

import numpy as np
import matplotlib.pyplot as plt
X = np.array([0,1,2])
Y = np.array([0, -1, -2])
xx, yy = np.meshgrid(X,Y)
plt.plot(xx, yy,"s")
plt.show()

电流输出为

enter image description here

预期输出为

enter image description here

推荐答案

我try 提出以下解决方案.假设我们有1x1平方,则不需要meshgrid:

import numpy as np
import matplotlib.pyplot as plt

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

X = np.array([0, 1, 2])
Y = np.array([0, -1, -2])

x_sorted = np.sort(X)
y_sorted = np.sort(Y)

ax.set_xticks(x_sorted)
ax.set_yticks(y_sorted)

ax.set_xlim(x_sorted[0], x_sorted[-1])
ax.set_ylim(y_sorted[0], y_sorted[-1])

ax.grid()

ax.set_aspect('equal', 'box')

plt.show()

enter image description here

Python相关问答推荐

从列表中获取n个元素,其中list [i][0]== value''

如何创建引用列表并分配值的Systemrame列

一个telegram 机器人应该发送一个测验如何做?""

删除特定列后的所有列

python的文件. truncate()意外地没有截断'

为什么后跟inplace方法的`.rename(Columns={';b';:';b';},Copy=False)`没有更新原始数据帧?

BeatuifulSoup从欧洲志愿者服务中获取数据和解析:一个从EU-Site收集机会的小铲子

启动线程时,Python键盘模块冻结/不工作

在任何要保留的字段中添加引号的文件,就像在Pandas 中一样

如何强制SqlalChemy指向与连接字符串的默认架构不同的架构

Python-迭代PANAS中的数据框并替换列表中不包含字符串的值

达到最大的Python Webhost资源

有可能得到事实的最后特征

导入pythoncom如何找到正确的文件?

Pandas 中的每行布尔运算

带参数约束的类型提示函数*args->;tuple[*args]

安装句子转换器时出错

是否 Select 所有整型列,除了几个python-polars列?

POLARS:从GROUP_BY列表中 Select 值,并从另一列中 Select 值

如何对牛郎星中的径向曲线值进行任意排序?