seaborn

Map value to specific colour in seaborn heatmap

烈酒焚心 提交于 2019-12-30 03:19:05
问题 I am plotting a heatmap in Python with the seaborn package. The values I am plotting are discrete, they are the integers -1 , 0 , and 1 . I would like the cells in the heatmap with the value -1 to show up green, those with 0 as yellow, and 1 as red. Is it possible to specify this ruling in the cubehelix_palette() or colour_palette() functions? 回答1: You can use matplotlib's ListedColormap as follows: import numpy as np import seaborn as sns from matplotlib.colors import ListedColormap data =

How to plot a heatmap from pandas DataFrame

不打扰是莪最后的温柔 提交于 2019-12-30 02:33:07
问题 Here is my dataframe: jan f m a m j \ 2000 -7.894737 22.387006 22.077922 14.5455 15.8038 -3.33333 2001 -3.578947 11.958763 28.741093 5.05415 74.7151 11.2426 2002 -24.439661 -2.570483 1.810242 8.56044 84.5474 -26.9753 2003 14.410453 -10.106570 8.179654 -11.6469 -15.0022 -13.9757 2004 -3.978623 -13.280310 2.558639 -1.13076 12.7156 -4.47235 2005 2.018146 1.385053 9.461930 14.1947 -10.4865 -11.1553 2006 -6.528617 -5.506220 -2.054323 1.39073 7.74041 -0.328937 2007 -1.634891 8.923088 4.951521 -1

Seaborn chart colors are different than those specified by palette

对着背影说爱祢 提交于 2019-12-29 08:48:06
问题 Why are seaborn chart colors different from the colors specified by the palette? The following two charts show the difference between the colors as they appear on a bar chart, and the colors as they appear in the palette plot. You can see if yo ulook carefully, that the colors on the bar chart are slightly less bright/saturated. Why are these different, and how can I get the bar chart to have the exact same colors as the ones specified in the palette? import seaborn as sns sns.set(style=

Show dates on seaborn heatmap

帅比萌擦擦* 提交于 2019-12-29 08:20:34
问题 I am trying to create a heat map from pandas dataframe using seaborn library. Here, is the code: test_df = pd.DataFrame(np.random.randn(367, 5), index = pd.DatetimeIndex(start='01-01-2000', end='01-01-2001', freq='1D')) ax = sns.heatmap(test_df.T) ax.xaxis.set_major_locator(mdates.MonthLocator()) ax.xaxis.set_minor_locator(mdates.DayLocator()) ax.xaxis.set_major_formatter(mdates.DateFormatter('%b')) ax.xaxis.set_minor_formatter(mdates.DateFormatter('%d')) However, I am getting a figure with

How to format seaborn/matplotlib axis tick labels from number to thousands or Millions? (125,436 to 125.4K)

孤者浪人 提交于 2019-12-29 07:34:25
问题 import matplotlib.pyplot as plt import matplotlib.ticker as ticker import seaborn as sns import pandas as pd sns.set(style="darkgrid") fig, ax = plt.subplots(figsize=(8, 5)) palette = sns.color_palette("bright", 6) g = sns.scatterplot(ax=ax, x="Area", y="Rent/Sqft", hue="Region", marker='o', data=df, s=100, palette= palette) g.legend(bbox_to_anchor=(1, 1), ncol=1) g.set(xlim = (50000,250000)) How can I can change the axis format from a number to custom format? For example, 125000 to 125.00K

how to order seaborn pointplot

时光毁灭记忆、已成空白 提交于 2019-12-28 18:50:23
问题 Here's code from kaggle Titanic competition kernel: grid = sns.FacetGrid(train_df, row='Embarked', size=2.2, aspect=1.6) grid.map(sns.pointplot, 'Pclass', 'Survived', 'Sex', palette='deep') grid.add_legend() It produces wrong plot, the one with reversed colors. I'd like to know how to fix this exact code fragment . I tried adding keyword paramas to grid.map() call - order=["male", "female"], hue_order=["male", "female"] , but then plots become empty. 回答1: In the code call to grid.map(sns

Annotate bars with values on Pandas (on Seaborn factorplot bar plot)

左心房为你撑大大i 提交于 2019-12-28 06:49:54
问题 I wrote some code to try and solve this question: https://stackoverflow.com/questions/39477748/how-to-annotate-bars-with-values-on-pandas-on-seaborn-factorplot-bar-plot I used part of the code that can be found here: matplotlib advanced bar plot Why is the graph so small? The code just tells to grab the accuracies from Pandas dataframe . The code: sns.set(style="white") g = sns.factorplot(x="Stages", y="Accuracy", hue="Dataset", data=df, saturation = 5, size=4, aspect=2, kind="bar", palette=

Seaborn tsplot does not show datetimes on x axis well

 ̄綄美尐妖づ 提交于 2019-12-28 03:50:12
问题 Below I have the following script which creates a simple time series plot: %matplotlib inline import datetime import pandas as pd import seaborn as sns import matplotlib.pyplot as plt fig, ax = plt.subplots() df = [] start_date = datetime.datetime(2015, 7, 1) for i in range(10): for j in [1,2]: unit = 'Ones' if j == 1 else 'Twos' date = start_date + datetime.timedelta(days=i) df.append({ 'Date': date.strftime('%Y%m%d'), 'Value': i * j, 'Unit': unit }) df = pd.DataFrame(df) sns.tsplot(df, time

How to optimize this Pandas code to run faster

独自空忆成欢 提交于 2019-12-27 01:24:07
问题 I have this code to create a swarmplot from data from a DataFrame: df = pd.DataFrame({"Refined__Some_ID":some_id_list, "Refined_Age":age_list, "Name":name_list } ) #Creating dataframe with strings from the lists select = df.apply(lambda row : any([isinstance(e, str) for e in row ]),axis=1) #Exlcluding data from select in a new dataframe dfAnalysis = df[~select] dfAnalysis['Refined_Age'].replace('', np.nan, inplace=True) dfAnalysis = dfAnalysis.dropna() dfAnalysis['Refined_Age'] = dfAnalysis[

python Seaborn - annotations with pointplot

橙三吉。 提交于 2019-12-25 17:17:16
问题 I am using a pointplot in seaborn. import seaborn as sns sns.set_style("darkgrid") tips = sns.load_dataset("tips") ax = sns.pointplot(x="time", y="total_bill", hue="smoker",data=tips) I would like to annotate all of the points. If there are points in between, I would like to label the points in between along with the line ends if that makes sense. Thank you so much! 回答1: The question is rather unspecific, but here is how to label each point in a pointplot, just as you would do with any other