How do I set color to Rectangle in Matplotlib?

I couldn’t get your code to work, but hopefully this will help: import matplotlib import matplotlib.pyplot as plt fig = plt.figure() ax = fig.add_subplot(111) rect1 = matplotlib.patches.Rectangle((-200,-100), 400, 200, color=”yellow”) rect2 = matplotlib.patches.Rectangle((0,150), 300, 20, color=”red”) rect3 = matplotlib.patches.Rectangle((-300,-50), 40, 200, color=”#0099FF”) circle1 = matplotlib.patches.Circle((-200,-250), radius=90, color=”#EB70AA”) ax.add_patch(rect1) ax.add_patch(rect2) ax.add_patch(rect3) ax.add_patch(circle1) plt.xlim([-400, 400]) plt.ylim([-400, 400]) … Read more

Plotting Pandas Multiindex Bar Chart

import pandas as pd data = pd.DataFrame([ (‘Q1′,’Blue’,100), (‘Q1′,’Green’,300), (‘Q2′,’Blue’,200), (‘Q2′,’Green’,350), (‘Q3′,’Blue’,300), (‘Q3′,’Green’,400), (‘Q4′,’Blue’,400), (‘Q4′,’Green’,450), ], columns=[‘quarter’, ‘company’, ‘value’] ) data = data.set_index([‘quarter’, ‘company’]).value data.unstack().plot(kind=’bar’, stacked=True) If you don’t want to stack your bar chart: data.unstack().plot(kind=’bar’)

Grouped Bar graph Pandas

Using pandas: import pandas as pd groups = [[23,135,3], [123,500,1]] group_labels = [‘views’, ‘orders’] # Convert data to pandas DataFrame. df = pd.DataFrame(groups, index=group_labels).T # Plot. pd.concat( [ df.mean().rename(‘average’), df.min().rename(‘min’), df.max().rename(‘max’) ], axis=1, ).plot.bar()

Is it possible to draw a boxplot given the percentile values instead of the original inputs?

As of 2020, there is a better method than the one in the accepted answer. The matplotlib.axes.Axes class provides a bxp method, which can be used to draw the boxes and whiskers based on the percentile values. Raw data is only needed for the outliers, and that is optional. Example: import matplotlib.pyplot as plt fig, … Read more

Seaborn lmplot with equation and R2 text

This now can be done using FacetGrid methods .map() or .map_dataframe(): import seaborn as sns import scipy as sp tips = sns.load_dataset(‘tips’) g = sns.lmplot(x=’total_bill’, y=’tip’, data=tips, row=’sex’, col=”time”, height=3, aspect=1) def annotate(data, **kws): r, p = sp.stats.pearsonr(data[‘total_bill’], data[‘tip’]) ax = plt.gca() ax.text(.05, .8, ‘r={:.2f}, p={:.2g}’.format(r, p), transform=ax.transAxes) g.map_dataframe(annotate) plt.show()

Single legend for multiple axes [duplicate]

I figured it a solution that works! Is there a better way than this? fig1.suptitle(‘Test’) ax1 = fig1.add_subplot(221) ax1.plot(x,y1,color=”b”,label=”aVal”) ax2 = ax1.twinx() ax2.plot(x,y2,color=”g”,label=”bVal”) ax2.grid( ls=”–“, color=”black”) h1, l1 = ax1.get_legend_handles_labels() h2, l2 = ax2.get_legend_handles_labels() ax1.legend(h1+h2, l1+l2, loc=2)