Python 将字符串赋给条件中的变量会导致错误

Python 将字符串赋给条件中的变量会导致错误,python,pandas,matplotlib,Python,Pandas,Matplotlib,我想为散点图创建一个动态标记类型。所以,我有这样的想法: import numpy as np import pandas as pd import matplotlib.pyplot as plt x = pd.DataFrame(np.random.randint(20,40,size=(5,1))) y = pd.DataFrame(np.random.randint(24,26,size=(5,1))) if x <= 30: marker_type = 'o' and fil

我想为散点图创建一个动态标记类型。所以,我有这样的想法:

import numpy as np
import pandas as pd
import matplotlib.pyplot as plt

x = pd.DataFrame(np.random.randint(20,40,size=(5,1)))
y = pd.DataFrame(np.random.randint(24,26,size=(5,1)))

if x <= 30:
marker_type = 'o' and fill_type = 'full' and label_type = "var <= 30"
if x > 30 and symbols_x <= 40:
marker_type = 'o' and fill_type = 'none' and label_type = "30 < var <= 40"

plot = plt.figure(1)
plt.scatter(x, y, marker=marker_type, fill=fill_type, label=label_type)
legend = plot.legend(loc='upper right')
plot.show()
将numpy导入为np
作为pd进口熊猫
将matplotlib.pyplot作为plt导入
x=pd.DataFrame(np.random.randint(20,40,size=(5,1)))
y=pd.DataFrame(np.random.randint(24,26,size=(5,1)))

如果x30和符号_x如果按如下所示进行if循环,则此错误将消失

if x <= 30:
    marker_type = 'o' 
    fill_type = 'full' 
    label_type = "var <= 30"
else:
    pass
if x > 30 and symbols_x <= 40:
    marker_type = 'o' 
    fill_type = 'none' 
    label_type = "30 < var <= 40"
else:
    pass

如果x 30和符号\u x,你想做什么<代码>散布
没有
填充
?@QuangHoang我相信
填充
应该是
填充样式
。这是指散点图的实际标记散点图也没有
fillstyles
参数。中列出了可能的参数。我正在寻找
facecolors
edgecolors
以获得所需的效果。我想我是从Matlab那里得到了
fill
。考虑到问题的大部分代码都没有意义,也许你想更新?特别是,您可能会评论为什么不简单地绘制2个散点,一个用于大于30的值,一个用于小于30的值。我明白您分配整个数据帧的意思,但即使我执行类似于x[0](只调用一列)的操作,我仍然会遇到错误您无法确定一组数字是否大于单个数字。(试想一下如果[1,2,5,6]>3
,你对
有什么期望?有些数字更小,有些更大。)是的,但我希望更大的数字会受到条件的影响。当然有办法做到这一点。