seaborn

Seaborn Countplot : Display only n most frequent categories

為{幸葍}努か 提交于 2019-12-11 16:36:49
问题 I have a python array listing all occurences of string labels. Let's call it labels_array. Using seaborn as sns I d like to show a countplot of this array : sns.countplot(labels_array) This works, but as they are too many different labels in my array, the outpout doesnt look good. Is there a way to display only the n most frequent labels. 回答1: Although countplot should in principle know the counts and hence allow to show only part of them, this is not the case. Therefore, the use of countplot

How to plot multiple line charts from a Pandas data frames

我的未来我决定 提交于 2019-12-11 15:50:06
问题 I'm trying to make an array of line charts from a data frame like this import pandas as pd import numpy as np import matplotlib.pyplot as plt df = pd.DataFrame({ 'CITY' : np.random.choice(['PHOENIX','ATLANTA','CHICAGO', 'MIAMI', 'DENVER'], 10000), 'DAY': np.random.choice(['Monday','Tuesday','Wednesday', 'Thursday', 'Friday', 'Saturday', 'Sunday'], 10000), 'TIME_BIN': np.random.randint(1, 86400, size=10000), 'COUNT': np.random.randint(1, 700, size=10000)}) df['TIME_BIN'] = pd.to_datetime(df[

seaborn barplot: vary color with x and hue

痞子三分冷 提交于 2019-12-11 15:22:46
问题 My dataset contains information on the short-term and long-term effects of a decision support model. I would like to plot this in a barplot, with 4 bars: model on, short term model on, long term model off, short term model on, long term here is some sample code: df = pd.DataFrame(columns=["model", "time", "value"]) df["model"] = ["on"]*2 + ["off"]*2 df["time"] = ["short", "long"] * 2 df["value"] = [1, 10, 2, 4] sns.barplot(data=df, x="model", hue="time", y="value") plt.show() it looks like

seaborn plot misplotting x axis dates from pandas

我的未来我决定 提交于 2019-12-11 15:15:49
问题 I am trying to plot a lineplot in seaborn with values for the y axis and dates for the x axis coming from a pandas dataframe. When I create the lineplot without converting the date column to datetime object it puts the dates in the wrong order. When I do convert the date column to datetime format it gives strange x labels and only shows 5 of the dates. df = pd.read_csv("dddd.csv") df["date"] = pd.to_datetime(df["date"]) df = df.sort_values(["date"]) ax = sns.lineplot(y=df["google"],x=df["date

Plotting pre aggregated data in python

一笑奈何 提交于 2019-12-11 15:14:41
问题 I have a list of pre aggregated tuples: [{'target_y_n': 0, 'value': 0.5, 'count':1000},{'target_y_n': 1, 'value': 1, 'count':10000}, ...] How can I visualize the distributions (https://seaborn.pydata.org/generated/seaborn.distplot.html) or get frequency plots without re-expanding the aggregated representation to k copies of each value, but still re-using as much as possible from existing tools like distplot, countplot ? edit In R http://www.amitsharma.in/post/cumulative-distribution-plots-for

AtributeError: 'module' object has no attribute 'plt' - Seaborn

限于喜欢 提交于 2019-12-11 14:59:39
问题 I'm very new with these libraries and i'm having troubles while plotting this: import pandas as pd import seaborn as sns import matplotlib.pyplot as plt import numpy as np import random df5 = pd.read_csv('../../../../datos/tiempos-exacto-variando-n-m0.csv', sep=', ', engine='python') print(df5) df5['n'] = df5['n'].apply(lambda x: x**2) sns.jointplot(df5['n'], df5['tiempoTotal'], kind="reg") sns.plt.show() And i'm getting this output: n m tiempoTotal 0 1 0 2274 1 2 0 3370 2 3 0 5709 3 4 0 8959

How to add seaborn axes to matplotlib figure with subplots?

大兔子大兔子 提交于 2019-12-11 14:12:11
问题 I have a function to return a seaborn plot. I want to add multiple seaborn plots to a figure by looping. I found an answer here for matplotlib but not sure how to apply it to seaborn. import pandas as pd import numpy as np import seaborn as sns from matplotlib import pyplot as plt def plotf(df_x): g = sns.lineplot(data=df_x[['2016','2017','2018']]) g.set_xticks(range(0,12)) g.set_xticklabels(['Feb','Mar','Apr','May','Jun','Jul','Aug','Sep','Oct','Nov','Dec','Jan']) return g df = pd.DataFrame(

Adjust different transparency for different class in seaborn scatter plot

一个人想着一个人 提交于 2019-12-11 12:32:50
问题 I want different alpha value (transparency) for Different Class in scatter plot. sns.scatterplot(x="BorrowerAPR", y="LoanOriginalAmount", data=df_new, alpha=0.03, hue="LoanStatus") Expecting Class 1 alpha to be 0.2. 回答1: One way is to plot them separately, though you'll get different hues if not specified. Here's an example from the built-in tips dataset with different alpha values for smokers and non-smokers: import seaborn as sns import numpy as np tips = sns.load_dataset("tips") tips[

Bar chart in seaborn

家住魔仙堡 提交于 2019-12-11 12:27:55
问题 I am working with seaborn, and trying to make my bar chart look better. import numpy as np import matplotlib.pyplot as plt import seaborn as sns x = ['One', 'Two', 'Three', 'Four', 'Five'] y = [2, 3, 0, 4.5, 4] y2 = [0, 0, -5, 0, 0] sns.axes_style('white') sns.set_style('white') b = sns.barplot(x,y,color='pink') sns.barplot(x,y2, color='red') for p in b.patches: b.annotate( s='{:.1f}'.format(p.get_height()), xy=(p.get_x()+p.get_width()/2.,p.get_height()), ha='center',va='center', xytext=(0,10

Row based chart plot (Seaborn or Matplotlib)

坚强是说给别人听的谎言 提交于 2019-12-11 12:26:58
问题 Given that my data is a pandas dataframe and looks like this: Ref +1 +2 +3 +4 +5 +6 +7 2013-05-28 1 -0.44 0.03 0.06 -0.31 0.13 0.56 0.81 2013-07-05 2 0.84 1.03 0.96 0.90 1.09 0.59 1.15 2013-08-21 3 0.09 0.25 0.06 0.09 -0.09 -0.16 0.56 2014-10-15 4 0.35 1.16 1.91 3.44 2.75 1.97 2.16 2015-02-09 5 0.09 -0.10 -0.38 -0.69 -0.25 -0.85 -0.47 How can I plot a chart of the 5 lines (1 for each ref), where the X axis are the columns (+1, +2...), and starts from 0? If is in seaborn, even better. But