Issue
Using the Fifa 19 dataset, I'm trying to place the number of players within specific skill score intervals as labels on a histogram graph.
I'm reading the CSV file locally, although I put the URL link below to exemplify.
import numpy as np
import pandas as pd
import matplotlib.pyplot as plt
fifa_df = pd.read_csv('https://raw.githubusercontent.com/KeithGalli/matplotlib_tutorial/master/fifa_data.csv')
bins = np.arange(40,101,10)
plt.figure(figsize=(8,5), dpi=300)
bar_plot = plt.hist(fifa_df['Overall'], bins=bins)
plt.bar_label(bar_plot)
plt.xticks(bins)
plt.show()
This is the error I'm getting:
AttributeError: 'tuple' object has no attribute 'patches'
I need help with the error and also the logic of this function (I'm new to pyplot). I read answers to other questions and I don't quite seem to find the proper solution.
Solution
Change bar_plot = plt.hist(fifa_df['Overall'], bins=bins)
to count, n_bins, bar_plot = plt.hist(fifa_df['Overall'], bins=bins)
The plt.hist
returns a tuple of things, instead of the container you need for bar_label
.
Answered By - ym3141
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.