- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我制作了一个程序,它进行随机游走并绘制它。它运行良好,但每次运行程序时我都会收到警告。它说:
MatplotlibDeprecationWarning:
Adding an axes using the same arguments as a previous axes currently reuses the earlier instance.
In a future version, a new instance will always be created and returned. Meanwhile, this warning can be suppressed,
and the future behavior ensured, by passing a unique label to each axes instance.
rw_visual.py
中的 x 和 y 轴时,警告警告我
random_walk.py
(如果你需要测试它):
from random import choice
class RandomWalk():
"""A class to generate random walks."""
def __init__(self, num_points=5000):
"""Initialize attributes of a walk."""
self.num_points = num_points
# All walks start at (0, 0).
self.x_values = [0]
self.y_values = [0]
def fill_walk(self):
"""Calculate all the points in the walk."""
# Keep taking steps until the walk reaches the desired length.
while len(self.x_values) < self.num_points:
# Decide which direction to go and how far to go in that direction.
x_direction = choice([1, -1])
x_distance = choice([0, 1, 2, 3, 4])
x_step = x_direction * x_distance
y_direction = choice([1, -1])
y_distance = choice([0, 1, 2, 3, 4])
y_step = y_direction * y_distance
# Reject moves that go nowhere.
if x_step == 0 and y_step == 0:
continue
# Calculate the next x and y values.
next_x = self.x_values[-1] + x_step
next_y = self.y_values[-1] + y_step
self.x_values.append(next_x)
self.y_values.append(next_y)
rw_visual.py
(发生警告的地方):
import matplotlib.pyplot as plt
from random_walk import RandomWalk
# Keep making new walks, as long as the program is active.
while True:
# Make random walk, and plot the points.
rw = RandomWalk()
rw.fill_walk()
point_numbers = list(range(rw.num_points))
plt.scatter(rw.x_values, rw.y_values, c=point_numbers, cmap=plt.cm.Blues,
edgecolor='none', s=10)
# Emphasize the first and last points.
plt.scatter(0, 0, c='green', edgecolors='none', s=150)
plt.scatter(rw.x_values[-1], rw.y_values[-1], c='red', edgecolors='none',
s=150)
# Remove the axes.
plt.axes().get_xaxis().set_visible(False) # This is what it warns me about, I think.
plt.axes().get_yaxis().set_visible(False) # It also warns me about this.
plt.show()
keep_running = input("Make another walk? (y/n): ")
if keep_running == 'n':
break
最佳答案
plt.axes()
激活已经创建的轴(这是在您执行 plt.scatter
时创建的)。警告告诉您,在 future 的版本中,它不会激活已经创建的轴,而是创建一个新的轴实例。
您可能想要的是获取当前正在使用的轴。您可以使用 plt.gca()
轻松完成此操作.
所以更换
plt.axes().get_xaxis().set_visible(False)
plt.axes().get_yaxis().set_visible(False)
plt.gca().get_xaxis().set_visible(False)
plt.gca().get_yaxis().set_visible(False)
关于python - Matplotlib - MatplotlibDeprecationWarning,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52121498/
我正在尝试从数据集创建一个箱线图,然后更改每个子图的背景颜色: url = "https://raw.githubusercontent.com/jbrownlee/Datasets/master/i
我制作了一个程序,它进行随机游走并绘制它。它运行良好,但每次运行程序时我都会收到警告。它说: MatplotlibDeprecationWarning: Adding an axes using th
我遇到了一个警告,该警告仅在运行 pyinstaller 可执行文件时出现。 ...appdata\local\programs\python\python37-32\lib\site-package
我在 python3.6 中使用 matplotlib。我的程序运行成功,但它显示以下警告消息: /home/sree/python/PyPrgm.py:41:MatplotlibDeprecatio
我是 Python 编程的新手,但在尝试从 RAVDESS 数据集 wav 文件绘制频谱图时,我一直在与这些错误作斗争。这是代码; `for file in range(0 , len(listOfF
我是一名优秀的程序员,十分优秀!