This is my data inside my PostgreSQL. I need to create a bar chart (y-axis: number of post, x-axis: student_id). so I run SQL Script in Python and visualise using python.
here is my code:
import psycopg2
import pandas as pd
import matplotlib.pyplot as plt
con = psycopg2.connect(
host = "",
database="",
port="",
user = "",
password = "")
cur = con.cursor()
query= 'select student_id, count(student_id) as numberpost from forum group by student_id'
df=pd.read_sql(query,con)
plt.bar(x=df['student_id'],
height=df['numberpost'])
plt.xticks(rotation = 45)
plt.show()
However, I didn't get the output as I want. This is the output that I get.
It should be student_id data in the x-axis, and numberpost data in the y-axis.
Anyone can help me how to solve this problem?



plt.bar(x=df['student_id'].to_string(), ...xticksaccordingly, try searching for that