How to sort bar chart from larger to smaller value

Asked

Viewed 183 times

0

I have made the following chart. I would like to sort from the highest to the lowest value.

fig, ax = plt.subplots(figsize=(8,5))
sns.countplot(olist_geolocation['geolocation_state'])
plt.title('Compras por Estado', fontsize=16, fontweight='bold')
ax.set_xlabel('UF', fontsize=12, fontweight='bold')
ax.set_ylabel('Quantidade', fontsize=12, fontweight='bold')
plt.show()

inserir a descrição da imagem aqui

  • You can update your post with a print(olist_geolocation['geolocation_state']) and print(type(olist_geolocation['geolocation_state'])). If it is Series type, an sort_values() would solve.

  • I am using pandas and matplotlib. The Sort method also fits this need?

  • Yes, you can do the Sort on the dataframe. But sort_values is for Series type only

1 answer

-6

(function (global, factory) {
  typeof exports === 'object' && typeof module !== 'undefined' ? module.exports = factory(require('@popperjs/core')) :
  typeof define === 'function' && define.amd ? define(['@popperjs/core'], factory) :
  (global = typeof globalThis !== 'undefined' ? globalThis : global || self, global.bootstrap = factory(global.Popper));
}(this, (function (Popper) { 'use strict';

  function _interopNamespace(e) {
    if (e && e.__esModule) return e;
    var n = Object.create(null);
    if (e) {
      Object.keys(e).forEach(function (k) {
        if (k !== 'default') {
          var d = Object.getOwnPropertyDescriptor(e, k);
          Object.defineProperty(n, k, d.get ? d : {
            enumerable: true,
            get: function () {
              return e[k];
            }
          });
        }
      });
    }
    n['default'] = e;
    return Object.freeze(n);
  }

  var Popper__namespace = /*#__PURE__*/_interopNamespace(Popper);

  function _defineProperties(target, props) {
    for (var i = 0; i < props.length; i++) {
      var descriptor = props[i];
      descriptor.enumerable = descriptor.enumerable || false;
      descriptor.configurable = true;
      if ("value" in descriptor) descriptor.writable = true;
      Object.defineProperty(target, descriptor.key, descriptor);
    }
  }

  function _createClass(Constructor, protoProps, staticProps) {
    if (protoProps) _defineProperties(Constructor.prototype, protoProps);
    if (staticProps) _defineProperties(Constructor, staticProps);
    return Constructor;
  }
  • Is that javascript? The question was asked in python and is about sorting the data of a matplot dataframe displayed.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.