我使用以下代码绘制一些数据:
self.arms = df['arms'].iloc[-self.plotlength:]
self.armsup = [0 if i < 1.0 else log(i, 10) for i in self.arms]
self.armsdn = [0 if i > 1.0 else log(i, 10) for i in self.arms]
a1.plot(self.x, self.openarms - 1, color='k')
a1.vlines(self.x, 0, self.armsup, color='g')
a1.vlines(self.x, 0, self.armsdn, color='r')
直方图目前以零为中心。它应该以一个为中心。目前我正在通过减去一个来调整数据。如何绘制在一个任意数字之上和之下摆动的垂直线?
答案 0 :(得分:2)
看起来你正在记录self.arms
中的每个值,并且你知道中值应该是1.0左右。而不是
self.arms = df['arms'].iloc[-self.plotlength:]
self.armsup = [0 if i < 1.0 else log(i, 10) for i in self.arms]
self.armsdn = [0 if i > 1.0 else log(i, 10) for i in self.arms]
你可以使用
self.arms = df['arms'].iloc[-self.plotlength:]
self.armsup = [1.0 if log(i, 10) < 1.0 else log(i, 10) for i in self.arms]
self.armsdn = [1.0 if log(i, 10) > 1.0 else log(i, 10) for i in self.arms]
或类似地,使用NumPy:
self.arms = df['arms'].iloc[-self.plotlength:]
log_arms = np.log(self.arms)
threshold = 1
mask = log_arms > threshold
armsup = np.where(mask, log_arms, threshold)
armsdn = np.where(~mask, log_arms, threshold)
np.where
有调用签名np.where(cond, x, y)
,其中cond
是布尔数组,x
和y
是与cond
长度相同的数组,np.where(cond, x, y)
返回x
cond
为真的y
和cond
import numpy as np
import matplotlib.pyplot as plt
N = 100
arms = np.random.uniform(0.5, 4.0, N)
log_arms = np.log(arms)
threshold = 1
mask = log_arms > threshold
armsup = np.where(mask, log_arms, threshold)
armsdn = np.where(~mask, log_arms, threshold)
fig, ax = plt.subplots()
x = np.arange(N)
ax.vlines(x, threshold, armsup, color='g')
ax.vlines(x, armsdn, threshold, color='r')
plt.show()
为假的值。
例如,
getWindow().addFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_NAVIGATION);