Dance Party2
Dance Party2

Reputation: 7536

Matplotlib Markers as Tick Labels

Given the following code, I'd like to replace the y-tick label numbers with stars, the number of which corresponding to each number. For example, the top label should be 10 stars, aligned such that the last star is placed where the 0 in 10 currently resides. They need to be dynamically generated, meaning I want to avoid using plt.xticks(['**********',.....]):

import matplotlib.pyplot as plt

x = [1, 2]
y = [1, 4]
labels = ['Bogs', 'Slogs']
plt.plot(x, y, 'ro')
plt.xticks(x, labels, rotation='vertical')
plt.margins(0.2)
plt.subplots_adjust(bottom=0.15)
plt.show()

Here's basically what I'm trying to produce (dynamic numbers of stars per the underlying y-tick label values):

Like this Thanks in advance!

Upvotes: 0

Views: 1298

Answers (1)

Praveen
Praveen

Reputation: 7222

Don't actually write out the stars, then. When using a programming language, program! :-)

y_limit = 5
y_labels = ['*' * i for i in range(y_limit)]
plt.yticks(range(y_limit), y_labels)

Upvotes: 2

Related Questions