seaborn

twinx and sns.barplot seaborn are overlapping bars

白昼怎懂夜的黑 提交于 2019-12-13 08:12:47
问题 I would like to use sns.seaborn to display the np.sum and the np.mean on 2 different axes (with ax2 = ax1.twinx() I assume). The probem I have is that the graphs are overlapped and not readable. Am I approaching the problem correctly? What can I do to get those bars next to each other? import seaborn as sns tips = sns.load_dataset("tips") f, ax1 = plt.subplots() ax2 = ax1.twinx() sns.barplot(x="day", y="total_bill", data=tips, estimator=np.mean, ax=ax1) sns.barplot(x="day", y="total_bill",

Adding legend to a radarchart in Python

别等时光非礼了梦想. 提交于 2019-12-13 07:21:29
问题 I want to create a radarchart with legends for every plot that is created but until now it has been impossible. Then, you can see the code used to create the plot (thanks to another user that developed it). import numpy as np import matplotlib.pyplot as plt import seaborn as sns # improves plot aesthetics import pandas as pd def _invert(x, limits): """inverts a value x on a scale from limits[0] to limits[1]""" return limits[1] - (x - limits[0]) def _scale_data(data, ranges): """scales data[1:

Coordinates of boxes in Seaborn boxplot

谁说我不能喝 提交于 2019-12-13 06:09:33
问题 This example, extended here, shows how to label bar plots in Matplotlib; a similar idea can be used to label box plots. It relies on knowing the x and y coordinates of the bars, which are returned by the barplot function. How can I do the same thing for Seaborn box plots? Unfortunately Seaborn does not return these coordinates. 回答1: You can hack around a bit to find them, but its not pretty. sns.boxplot returns the matplotlib Axes instance the boxes are drawn on. The boxes are created as

Visualisation of missing-data occurrence frequency by using seaborn

柔情痞子 提交于 2019-12-13 04:17:14
问题 I'd like to create a 24x20 matrix(8 sections each has 60 cells or 6x10) for visualization of frequency of missing-data occurrence through cycles (=each 480-values ) in dataset via panda dataframe and plot it for each columns 'A' , 'B' , 'C' . So far I could map the create csv files and mapped the values in right way in matrix and plot it via sns.heatmap(df.isnull()) after changed the missing-data ( nan & inf ) into 0 or something like 0.01234 which has the least influence on data and in the

Grouped bar chart — how to make sns respect order of rows?

老子叫甜甜 提交于 2019-12-13 04:11:40
问题 I have a multilevel data frame, sorted by values on level=1 I want to make a grouped bar plot. When I do ax = sns.barplot(ax=ax, x="level0", y="values", hue="level1", data=data) Sns decides to sort index by level1. Is there a way to make sns respect the order of rows when making grouped bar plots? 回答1: As per the comment from @ImportanceOfBeingErnest, you can use the order and hue_order parameters to control in which order the bars appear along the x-axis. 来源: https://stackoverflow.com

How to get legend next to plot in Seaborn?

你离开我真会死。 提交于 2019-12-13 03:54:23
问题 I am plotting a relplot with Seaborn, but getting the legend (and an empty axis plot) printed under the main plot. Here is how it looks like (in 2 photos, as my screen isn't that big): Here is the code I used: fig, axes = plt.subplots(1, 1, figsize=(12, 5)) clean_df['tax_class_at_sale'] = clean_df['tax_class_at_sale'].apply(str) sns.relplot(x="sale_price_millions", y='gross_sqft_thousands', hue="neighborhood", data=clean_df, ax=axes) fig.suptitle('Sale Price by Neighborhood', position=(.5,1

Box plot of hourly data in Time Series Python

跟風遠走 提交于 2019-12-13 03:36:57
问题 How to group by a given frequency let say Hourly, and create a set of box plot for one column in a time series data set ? range = pd.date_range('2015-01-01', '2015-12-31', freq='1min') df = pd.DataFrame(index = range) # Average speed in miles per hour df['speed'] = np.random.randint(low=0, high=60, size=len(df.index)) # Distance in miles (speed * 0.5 hours) df['distance'] = df['speed'] * 0.25 # Cumulative distance travelled df['cumulative_distance'] = df.distance.cumsum() df.head() How to

Seaborn relplots creates duplicated axes

吃可爱长大的小学妹 提交于 2019-12-13 03:04:47
问题 I'am trying to create two plots - one under another with seaborn! My code: fig, (ax1, ax2) = plt.subplots(nrows=2, sharex=True, figsize=(22,8)) p1 = sns.relplot(x="sns_codes", y="triad_quantity", hue="label", data=data_2, kind="line", ax=ax1) p2 = sns.relplot(x="sns_codes", y="triad_quantity", hue="label", data=data_2, kind="line", ax=ax2) But this creates 4 axes instead of 2! Look: I give up getting read of these extra 2 axeses - need help. Here's code to create data: df ={'label': {0: 'top

Seaborn Heatmap with Datetime Axes

给你一囗甜甜゛ 提交于 2019-12-13 03:03:51
问题 I and to create a heatmap that will have year across the x axis and month across the y axis. In the heatmap will be % returns. Here's kinda what I am after. So I have some data and I turn them into pct_change() series. import pandas_datareader.data as web import pandas as pd from datetime import datetime as dt import numpy as np import seaborn as sns start = dt(year = 2000, month = 1, day = 1) df = web.DataReader('GDP', 'fred', start = '2000') df.pct_change() df.tail() So here's what we are

Remove one of the two legends produced in this Seaborn figure?

佐手、 提交于 2019-12-13 02:55:04
问题 I have just started using seaborn to produce my figures. However I can't seem to remove one of the legends produced here. I am trying to plot two accuracies against each other and draw a line along the diagonal to make it easier to see which has performed better (if anyone has a better way of plotting this data in seaborn - let me know!). The legend I'd like to keep is the one on the left, that shows the different colours for 'N_bands' and different shapes for 'Subject No' ax1 = sns.relplot(y