Whoops…Nothing found

Try other keywords in your search

Sorting Values in Legends/Axes

 0 Minutes



Currently, values within an axis are sorted alphabetically and cannot be changed within Explore (more user control over axes sorting to be added in a future release). Consider the graph below of chocolate bar sales across different locations:

Given the alphabetical sorting on the Y axis, the data from the other cities is highly overshadowed by the height of the data in Houston. We can sort these axes by adding a prefix to each of the locations using the code below:

df.Location = df.Location.replace('Los Angeles', '1 - Los Angeles')
df.Location = df.Location.replace('New York', '2 - New York')
df.Location = df.Location.replace('Houston', '3 - Houston')

Here we are using the Replace function from the Pandas Python package to replace all instances of one text string in the “Location” column with another. Alternatively, we could achieve this in Explore using the Find and Replace tool:

By simply adding a numerical prefix, Explore will now sort the locations in a way that is much more aesthetically pleasing:

Was this article helpful?