pandas plot value counts barplot in descending manner [duplicate]
You can do it by changing your plotting line like this df.letters.value_counts().sort_values().plot(kind = ‘barh’)
You can do it by changing your plotting line like this df.letters.value_counts().sort_values().plot(kind = ‘barh’)
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
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’)
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()
Installing matplotlib before installing pandas again made it work.
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
You can create custom polygons using the keyword argument marker and passing it a tuple of 3 numbers (number of sides, style, rotation). To create a triangle you would use (3, 0, rotation), an example is shown below. import matplotlib.pyplot as plt x = [1,2,3] for i in x: plt.plot(i, i, marker=(3, 0, i*90), markersize=20, … Read more
You can simply use figtext. You can also change the value of x and y-axes as you want. txt=”I need the caption to be present a little below X-axis” plt.figtext(0.5, 0.01, txt, wrap=True, horizontalalignment=”center”, fontsize=12)
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()
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)