Pandas dataframe groupby plot

Simple plot, you can use: df.plot(x=’Date’,y=’adj_close’) Or you can set the index to be Date beforehand, then it’s easy to plot the column you want: df.set_index(‘Date’, inplace=True) df[‘adj_close’].plot() If you want a chart with one series by ticker on it You need to groupby before: df.set_index(‘Date’, inplace=True) df.groupby(‘ticker’)[‘adj_close’].plot(legend=True) If you want a chart with individual … Read more

How can I change the font size using seaborn FacetGrid?

You can scale up the fonts in your call to sns.set(). import numpy as np import matplotlib.pyplot as plt import seaborn as sns x = np.random.normal(size=37) y = np.random.lognormal(size=37) # defaults sns.set() fig, ax = plt.subplots() ax.plot(x, y, marker=”s”, linestyle=”none”, label=”small”) ax.legend(loc=”upper left”, bbox_to_anchor=(0, 1.1)) sns.set(font_scale=5) # crazy big fig, ax = plt.subplots() ax.plot(x, y, … Read more

How to edit a seaborn legend title and labels for figure-level functions

Took me a while to read through the above. This was the answer for me: import seaborn as sns import matplotlib.pyplot as plt tips = sns.load_dataset(“tips”) g = sns.lmplot( x=”total_bill”, y=”tip”, hue=”smoker”, data=tips, legend=False ) plt.legend(title=”Smoker”, loc=”upper left”, labels=[‘Hell Yeh’, ‘Nah Bruh’]) plt.show(g) Reference this for more arguments: matplotlib.pyplot.legend

How to display custom values on a bar plot

New in matplotlib 3.4.0 There is now a built-in Axes.bar_label to automatically label bar containers: For single-group bar plots, pass the single bar container: ax = sns.barplot(x=’day’, y=’tip’, data=groupedvalues) ax.bar_label(ax.containers[0]) For multi-group bar plots (with hue), iterate the multiple bar containers: ax = sns.barplot(x=’day’, y=’tip’, hue=”sex”, data=df) for container in ax.containers: ax.bar_label(container) More details: How … Read more

Plot a histogram such that bar heights sum to 1 (probability)

If you want the sum of all bars to be equal unity, weight each bin by the total number of values: weights = np.ones_like(myarray) / len(myarray) plt.hist(myarray, weights=weights) Note for Python 2.x: add casting to float() for one of the operators of the division as otherwise you would end up with zeros due to integer … Read more

Move legend outside figure in seaborn tsplot [duplicate]

20220916 Update Since version v0.11.2 of seaborn, there is an in-built control of the legend position, see seaborn.move_legend. To put the legend outside: ax = sns.histplot(penguins, x=”bill_length_mm”, hue=”species”) sns.move_legend(ax, “upper left”, bbox_to_anchor=(1, 1)) Old Answer Indeed, seaborn doesn’t handle legends well so far. You can use plt.legend() to control legend properties directly through matplotlib, in … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)