def factor_plot(dataFrame, factors, prediction, color="Set3"):
# First, plot the total for each factor. Then, plot the total for each
# factor for the prediction variable (so in a conversion example, how
# many people converted, revenue per country, etc.)
# These refer to the rows and columns of the axis numpy array; not the
# data itself.
row = 0
column = 0
sns.set(style="whitegrid")
# TODO: Set the width based on the max number of unique
# values for the factors.
plots = plt.subplots(len(factors), 2, figsize=(8,12))
# It should
for factor in factors:
sns.countplot(x=factor, palette="Set3", data=dataFrame,
ax=plots[1][row][column])
# Then print the total for each prediction
sns.barplot(x=factor, y=prediction, data=dataFrame,
ax=plots[1][row][column+1])
row += 1
plt.tight_layout() # Need this or else plots will crash into each other
python类countplot()的实例源码
def weather_distribution(self):
data_dir = g_singletonDataFilePath.getTrainDir()
self.gapdf = self.load_weatherdf(data_dir)
print self.gapdf['weather'].describe()
# sns.distplot(self.gapdf['gap'],kde=False, bins=100);
sns.countplot(x="weather", data=self.gapdf, palette="Greens_d");
plt.title('Countplot of Weather')
# self.gapdf['weather'].plot(kind='bar')
# plt.xlabel('Weather')
# plt.title('Histogram of Weather')
return
Histogram_of_song_attributes.py 文件源码
项目:music-datamining
作者: SunnyShikhar
项目源码
文件源码
阅读 21
收藏 0
点赞 0
评论 0
def PlotBarChart(CategoricalVar, data, XName):
sns.countplot(CategoricalVar, data=data)
plt.xlabel(XName)
plt.title( XName + ' Bar Chart')
plt.show()
def explore_feature_variation(self, col=None, use_target=False, **kwargs):
'''
Produces univariate plots of a given set of columns. Barplots are used
for categorical columns while histograms (with fitted density functinos)
are used for numerical columns.
If use_target is true, then the variation of the given set of columns
with respect to the response variable are used (e.g., 2d scatter
plots, boxplots, etc).
Parameters
----------
col : a string of a column name, or a list of many columns names or
None (default). If col is None, all columns will be used.
use_target : bool, default False
Whether to use the target column in the plots.
**kwargs: additional arguments to be passed to seaborn's distplot or
to pandas's plotting utilities..
'''
self._validate_params(params_list = {'col':col},
expected_types= {'col':[str,list,type(None)]})
if type(col) is str: col = [col]
if col is None: col = self._get_all_features()
if use_target == False:
for column in col:
if self.is_numeric(self.df[column]) == True:
plt.figure(column)
#sns.despine(left=True)
sns.distplot(self.df[column], color="m", **kwargs)
plt.title(column)
plt.tight_layout()
#plt.figure('boxplot')
#sns.boxplot(x=self.df[col], palette="PRGn")
#sns.despine(offset=10, trim=True)
elif self.is_categorical(self.df[column]) == True:
#print self.df[column].describe()
plt.figure(column)
#sns.despine(left=True)
if len(self.df[column].unique()) > 30:
self.df[column].value_counts()[:20][::-1].plot.barh(**kwargs)
#top = pd.DataFrame(data=top)
#sns.barplot(y=top.index, x=top)
else:
self.df[column].value_counts()[::-1].plot.barh(**kwargs)
#sns.countplot(y=self.df[column])
plt.title(column)
plt.tight_layout()
else:
raise TypeError('TYPE IS NOT SUPPORTED')
else: # use target variable
for column in col:
self.explore_features_covariation(col1=column, col2=self.y, **kwargs)
data_manag&visualization.py 文件源码
项目:-Python-Analysis_of_wine_quality
作者: ekolik
项目源码
文件源码
阅读 24
收藏 0
点赞 0
评论 0
def countplots(wine_set):
wine_set["quality"] = pd.Categorical(wine_set["quality"])
seaborn.countplot(x="quality", data=wine_set)
plt.xlabel("Quality level of wine (0-10 scale)")
plt.show()
def variants_chrom(self):
''' Countplot of number of variants identified
across all chromosomes.
'''
self.pdvcf.remove_scaffolds()
plt.style.use('seaborn-deep')
fig, ax = plt.subplots(figsize=(14, 7))
sns.countplot(data=self.pdvcf.vcf, x='CHROM', palette='GnBu_d')
ax.tick_params(labelsize=15)
ax.set_ylabel('Variants', fontsize=20)
ax.set_xlabel('Chromosome', fontsize=20)
ax.set_title('Variants Identified Across Chromosomes', fontsize=25)
return ax