Как создать динамические гистограммы? (Подробности смотрите по ссылке на видео) - PullRequest
0 голосов
/ 05 мая 2019

Я хочу знать, как создавать динамические гистограммы, как показано в видео "https://www.youtube.com/watch?v=cKzP61Gjf00"

Я пытался использовать matplotlib (python) для создания чего-то похожего, но я не могу ввести динамические обновления.

Буду признателен за помощь здесь.

import os
import numpy as np
import matplotlib.pyplot as plt

x = [u'INFO', u'CUISINE', u'TYPE_OF_PLACE', u'DRINK', u'PLACE', u'MEAL_TIME', u'DISH', u'NEIGHBOURHOOD', u'New']
y = [360, 167, 137, 118, 120, 136, 155, 130, 380]
y.sort()

fig, ax = plt.subplots()    
width = 0.75 # the width of the bars 
ind = np.arange(len(y))  # the x locations for the groups
ax.barh(ind, y, width, color="cyan", zorder=2)
#ax.set_yticks(ind+width/2)
#ax.set_yticklabels(x, minor=False)

#Start --- remove ticks ---
ax.get_xaxis().set_ticks([])
ax.get_yaxis().set_ticks([])
#End --- remove ticks ---

#Start --- remove borders ---
ax.spines['top'].set_visible(False)
ax.spines['right'].set_visible(False)
ax.spines['bottom'].set_visible(False)
ax.spines['left'].set_visible(False)
#End --- remove borders ---

#Start --- Labelling axes and title ---
plt.title('title')
#plt.xlabel('x')
#plt.ylabel('y')      
#End --- Labelling axes and title ---
vline_value = 50
plt.axvline(x=vline_value, zorder=1, color='gray', linewidth=0.2)
x_bounds = ax.get_xlim()
ax.annotate(s=str(vline_value), xy =(((vline_value-x_bounds[0])/(x_bounds[1]-x_bounds[0])),1.01), xycoords='axes fraction', verticalalignment='center', horizontalalignment='center')
#plt.text(50.1,0,'blah',rotation=90)

for i, v in enumerate(y):
    ax.text(v+3, i, str(v), color='black', fontsize=7.5, va='center')

for i, v in enumerate(y):
    ax.text(5, i-0.125, str(x[i]), color='black', fontsize=8)

plt.show()

#plt.savefig(os.path.join('test.png'), dpi=300, format='png', bbox_inches='tight') # use format='svg' or 'pdf' for vectorial pictures
...