Home > Blockchain >  How to fill Pie chart with datas from MySql Datas
How to fill Pie chart with datas from MySql Datas

Time:08-29

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.

CodePudding user response:

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()

CodePudding user response:

Have to use flatten() after pie(x)

x = x.flatten()
  • Related