Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8703023
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T02:47:16+00:00 2026-06-13T02:47:16+00:00

When I create a DataFrame, then sort by a column it appears to be

  • 0

When I create a DataFrame, then sort by a column it appears to be sorted in the iteractive display (i.e. whatever repr gives), but when I call the DataFrame.plot() function it plots the unsorted array. Calling matplotlib.pylab.plot works fine though. I suspect it’s something to do with clever pointer rearrangement not being passed to whatever the plot function is calling to access the data … or maybe I’m just doing something dumb. I’ve tried this on pandas 0.8.1 (osx and linux with python2.7.something) and pandas 0.9.0 (osx with python3.something).

import pandas
import numpy
from matplotlib.pylab import *
a = numpy.random.randn(100,10)
df = pandas.DataFrame(a)
df.shape
df.sort(column=0)
df.columns
df.sort(column=0, inplace=True)
df[0]
df[0].plot()
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-13T02:47:17+00:00Added an answer on June 13, 2026 at 2:47 am

    Plotting is by default your data versus the index. In case of a numerical index, look at the index after sorting on a column. you might want to use plot(use_index=False). See example below.

    In [2]: df = pd.DataFrame(np.random.randn(10, 2), columns=['A', 'B'])
    
    In [3]: df
    Out[3]:
              A         B
    0 -0.938196  2.220319
    1 -0.022503  0.564602
    2  0.033094 -0.717969
    3  2.466486  1.229651
    4 -0.641596 -1.016921
    5  0.094125  1.531526
    6  0.579631  1.398635
    7 -0.854799 -0.930904
    8 -1.177894 -1.501657
    9  0.341655 -0.917243
    
    In [4]: df.sort(columns='A', inplace=True)
    Out[4]:
              A         B
    8 -1.177894 -1.501657
    0 -0.938196  2.220319
    7 -0.854799 -0.930904
    4 -0.641596 -1.016921
    1 -0.022503  0.564602
    2  0.033094 -0.717969
    5  0.094125  1.531526
    9  0.341655 -0.917243
    6  0.579631  1.398635
    3  2.466486  1.229651
    
    In [5]: df['A'].plot(use_index=False)
    Out[5]: <matplotlib.axes.AxesSubplot at 0xb56ac6c>
    

    enter image description here

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a state column in a dataframe and I want to create two
I'm looking to create a copy of an existing column in a dataframe that
I tried to create a dataframe of two columns with numbers, then create a
I want to be able to create a Pandas DataFrame with MultiIndexes for the
I am wondering if it is possible to create a new dataframe with certain
I am looking to remove multiple observations from one column within a dataframe based
I am still attempting to create a detailed time-series dataframe. I'm attempting to get
I am trying to display some information about the data below the plot created
I'd like to create a pandas DataFrame from the following csv file: ........... EUR
I'm an R/ggplot newbie. I would like to create a geom_line plot of a

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.