Matplotlib符号表示否定中的数据

2024-04-25 00:27:22 发布

您现在位置:Python中文网/ 问答频道 /正文

使用Matplotlib的符号函数时,我收到以下错误:

ERROR: Data has no positive values, and therefore can not be log-scaled.

然而,我的数据在y维度上都是正面的:

presvals ~= [1000  990  980  970  960  950  940  930  920  910  900 ... 10]

下面是我如何调用代码:

import sharppy.sharptab.thermo as thermo
imageScale = 2
fig = plt.figure(figsize=(6.5875*imageScale, 6.2125*imageScale))
ax = fig.add_subplot(111)
ax.grid(True)
pmax = 1000
pmin = 10
dp = -10
presvals = np.arange(int(pmax), int(pmin)+dp, dp)
tw = []
for p in presvals:
    tw.append(thermo.wetlift(1000., t, p))
ax.semilogy(tw, presvals, 'b-', alpha=.3)

我以前使用过这个精确的代码,它已经起作用了。有什么东西不见了吗?我试图格式化y轴,但没有任何帮助。如有任何方向可看,将不胜感激。你知道吗


Tags: 函数代码thermomatplotlib错误fig符号ax
1条回答
网友
1楼 · 发布于 2024-04-25 00:27:22

对我来说,这个代码是有效的:

import numpy as np
import matplotlib.pyplot as plt
%matplotlib inline

imageScale = 2
fig = plt.figure(figsize=(6.5875*imageScale, 6.2125*imageScale))
ax = fig.add_subplot(111)
ax.grid(True)
pmax = 1000
pmin = 10
dp = -10
presvals = np.arange(int(pmax), int(pmin)+dp, dp)
ax.semilogy(presvals, 'b-', alpha=.3)

所以我认为问题出在tw的定义上,我无法重现。。。你知道吗

相关问题 更多 >