对于函数中的循环以生成Barchart类的频率?
class Visualizer:
def __init__(self, dataframe):
self.df = dataframe
def plot_bar(self, x,height, width, title = " ",xlabel = " ", ylabel = " ",color = " ", **kwargs):
fig, ax = plt.subplots(figsize=(11, 9))
if type(x) == type("xyz"):
x = self.df[x].value_counts().index
plt.bar(x= x,
height= height,
width = width,
color= color,
alpha=0.5)
plt.xlabel(xlabel, fontsize = 20)
plt.ylabel(ylabel, fontsize = 20)
plt.xticks(fontsize = 16)
plt.yticks(fontsize = 16)
leg = plt.legend(loc='upper right', fancybox=True)
leg.get_frame().set_alpha(0.5)
plt.title(title, fontsize = 20)
plt.show()
我称此函数为下面:
vizu =visualization("df")
vizu.plot_bar("State",200, 0.25, " Area vs State", "Area","Rentalprice",'r' )
如何拥有一个循环,该循环在函数中生成列(状态)中的类频率? 另外,我将输出的屏幕截图作为参考。
这是我的第一个堆栈流问题。任何错误,请接受我的道歉!
class Visualizer:
def __init__(self, dataframe):
self.df = dataframe
def plot_bar(self, x,height, width, title = " ",xlabel = " ", ylabel = " ",color = " ", **kwargs):
fig, ax = plt.subplots(figsize=(11, 9))
if type(x) == type("xyz"):
x = self.df[x].value_counts().index
plt.bar(x= x,
height= height,
width = width,
color= color,
alpha=0.5)
plt.xlabel(xlabel, fontsize = 20)
plt.ylabel(ylabel, fontsize = 20)
plt.xticks(fontsize = 16)
plt.yticks(fontsize = 16)
leg = plt.legend(loc='upper right', fancybox=True)
leg.get_frame().set_alpha(0.5)
plt.title(title, fontsize = 20)
plt.show()
I call this function as below:
vizu =visualization("df")
vizu.plot_bar("State",200, 0.25, " Area vs State", "Area","Rentalprice",'r' )
How to have a loop which generates the frequency of classes in a column(state) within the function?
Also, I am attaching the screen shot of the output as the reference.
This is my 1st stack flow question. Any mistake, please accept my apologizes!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论