Module_10
- Angela Porcelli
- Mar 20, 2021
- 2 min read
Updated: Mar 21, 2021
Original Data: Create two simple visual graphs by using 1) Matplotlib (Links to an external site.) and 2) ggplot
For my visualizations, I am using data from Hillsborough County Pet and Resource Center which is their animal control. I took the data from the last two weeks of animal intakes. This data lists the type of animal (dog or cat) and the type of intake for each animal. Intakes can be for one of five reasons
Return - an adopter returns the animal for any reason
Owner Surrender - an animal's owner can no longer keep their pet
Stray - an animal on the street is either picked up by a HCPRC employee or brought in by an individual that is not the legal owner of the animal
Confiscate - HCPRC takes legal ownership of a pet that is deemed to be in an unsafe environment
Foster - the animal was being foster and is now ready to go up for adoption
Matplotlib:
import matplotlib import matplotlib.pyplot as plt import numpy as np labels = ['Return', 'Surrender', 'Stray', 'Confiscate', 'Foster'] Dogs = [2, 8, 29, 3, 2] Cats = [0, 3, 2, 1, 0] x = np.arange(len(labels)) # the label locations width = 0.35 # the width of the bars fig, ax = plt.subplots() rects1 = ax.bar(x - width/2, Dogs, width, label='Dogs', color='green') rects2 = ax.bar(x + width/2, Cats, width, label='Cats', color='purple') # Add some text for labels, title and custom x-axis tick labels, etc. ax.set_ylabel('Number of Intakes') ax.set_title('Intakes March 5th - 19th 2021', color='red') ax.set_xticks(x) ax.set_xticklabels(labels) ax.legend() def autolabel(rects): """Attach a text label above each bar in *rects*, displaying its height.""" for rect in rects: height = rect.get_height() ax.annotate('{}'.format(height), xy=(rect.get_x() + rect.get_width() / 2, height), xytext=(0, 3), # 3 points vertical offset textcoords="offset points", ha='center', va='bottom') autolabel(rects1) autolabel(rects2) fig.tight_layout() plt.show()

Find this on GitHub: https://github.com/aporcelli-LIS/Python/blob/main/Intake%20Graph.py
At a glance, this graph shows that dogs have a greater chance of entering the shelter and stray dogs are an issue for the county.
Ggplot:
After spending an entire day working on ggplot, I still have been unable to run this package. I have uninstalled and reinstalled ggplot, pandas, visual studio code, and python itself trying to figure this out. I keep running into errors with pandas and I cannot seem to fix this. I have watched several tutorials and read many blogs and chat rooms, but nothing has worked. The two consistent error messages I receive are
AttributeError: module 'pandas' has no attribute 'DataFrame'
AttributeError: module 'pandas' has no attribute 'core'
I feel that this is a lot of work for something that can be done just as well using Python's Matplotlib or R's ggplot. I'm going to keep working on this issue but as of now, I don't think the time justifies the end result. The code you see in the image below is not my own. To ensure that the issue didn't lie with my code, I used code with image of the output from the internet as my control. My reasoning is that if I can get code that has already been proven to run correctly to work in Virtual Studio Code, then the error must be within my code. However, I could not get the example code to run so I feel the error must be within the package or package installation.



Comments