Python Гистограмма - PullRequest
       3

Python Гистограмма

0 голосов
/ 07 февраля 2020

Я создал гистограмму в Python, я все правильно добавил, но не могу понять, как исправить ось х, поскольку она загромождена, и гистограмма выглядит грязной? Может кто-нибудь ввести, что изменить в коде и сделать его лучше? Я добавил свой код и как он выглядит сейчас.

import pandas as pd
import matplotlib.pyplot as plt
import numpy as np

#Get Data from CSV File.
data=pd.read_csv("raw_data.csv")
data.head()

#Plot on Bar Chart.
ax = data['AGE'].value_counts().plot('bar')

#Set Axis to show labels in correct rotation and set axis limit to 150.
plt.xticks(rotation=0, fontsize=14)
plt.yticks(rotation=0, fontsize=14)
plt.ylim(0,150)


#Label Graph and Axis 
width = 0.35
plt.title("Ages of Male and Female Participants", fontsize=18)
plt.xlabel("Age", fontsize=18)
plt.ylabel("Frequency", fontsize=18)


#Remove description line above bar chart.
for t in ax.texts:
t.set_visible(False)

#Show the totals of each bar (with formatting).
for p in ax.patches:
ax.annotate("%i" % p.get_height(), (p.get_x() + p.get_width() / 2., p.get_height()), ha='center', va='center', xytext=(0, 10), fontsize=16, fontweight='bold', textcoords='offset points')

enter image description here

1 Ответ

0 голосов
/ 07 февраля 2020

Попробуйте использовать стиль из примера Matplotlib, может быть, это один !!

...