<jupyter_start><jupyter_text>When a **lollipop plot** shows the relationship between a numerical and a categorical variable, it might be better to re-order the groups on a decreasing order and display them **horizontally**.Note that the `stem()` function does not allow to plot horizontal lollipop plots, thus you need to use the `hlines()` function.<jupyter_code># libraries
import pandas as pd
import matplotlib.pyplot as plt
import numpy as np
 
# Create a dataframe
df = pd.DataFrame({'group':list(map(chr, range(65, 85))), 'values':np.random.uniform(size=20) })
 
# Reorder it based on the values
ordered_df = df.sort_values(by='values')
my_range=range(1,len(df.index)+1)
 
# The horizontal plot is made using the hline function
plt.hlines(y=my_range, xmin=0, xmax=ordered_df['values'], color='skyblue')
plt.plot(ordered_df['values'], my_range, "o")
 
# Add titles and axis names
plt.yticks(my_range, ordered_df['group'])
plt.title("A vertical lolipop plot", loc='left')
plt.xlabel('Value of the variable')
plt.ylabel('Group')

# Show the plot
plt.show()<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.1248852157943067, 'fraction_numerical': 0.008264462809917356, 'mean_word_length': 6.266666666666667, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '1', 'dir': 'jupyter-structured-clean-dedup', 'id': '383871', 'license': '0BSD', 'n_tokens_mistral': 371, 'n_tokens_neox': 349, 'n_words': 117, 'path': 'src/notebooks/182-vertical-lollipop-plot.ipynb', 'repo_name': 's-lasch/The-Python-Graph-Gallery', 'size': '1089'}