How to fill Pie chart with datas from MySql Datas

Question:

I got datas from MySql Database.

age_query = "SELECT age FROM test"
mycr.execute(wiek_query)
res = mycr.fetchall()

How to fill pie chart with "res" variable.
Type() shows me

print(type(res)) #list

When i do

x = np.array(res)
plt.pie(x)
plt.show()

i got error: ValueError: x must be 1D

What i have to do to fill Pie chart with res variable.

Asked By: Michał

||

Answers:

Have to use flatten() after pie(x)

x = x.flatten()
Answered By: Michał
import numpy as np
import matplotlib.pyplot as plt

a = np.array([[44], [23], [25], [39], [34], [20], [44], [31], [32], [42]], np.int32)

a = a.ravel()

plt.pie(a)
plt.show()
Answered By: Luka Banfi
Categories: questions Tags: ,
Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
at the top-right corner.