Matplotlib.
ipynb - Colab 26/05/24, 4:34 PM
Matplotlib
↳ 3 cells hidden
Importing library
[ ] ↳ 2 cells hidden
1. Creating and Customizing Our First Plots
[ ] ↳ 6 cells hidden
2. Bar Charts and Analyzing Data from CSVs
import numpy as np
[Link]("fivethirtyeight")
import [Link] as plt
[Link]("fivethirtyeight")
[Link](x_indexes - width, dev_y, width=width, color='#444444', label='All Devs')
ages_x = [25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35]
x_indexes = [Link](len(ages_x))
width = 0.25
dev_y = [38496, 42000, 46752, 49320, 53200,
56000, 62316, 64928, 67317, 68748, 73752]
[Link](x_indexes - width, dev_y, width=width, color='#444444', label='All Devs')
# Median Python Developer Salaries by Age
# We are using same ages_x
py_dev_y = [45372, 48876, 53850, 57287, 63016,
65998, 70003, 70000, 71496, 75370, 83640]
[Link](x_indexes, py_dev_y, width=width, color='#008fd5', label='Python')
# Median JavaScript Developer Salaries by Age
js_dev_y = [37810, 43515, 46823, 49293, 53437,
56373, 62375, 66674, 68745, 68746, 74583]
[Link] Page 1 of 7
[Link] - Colab 26/05/24, 4:34 PM
[Link](x_indexes + width, js_dev_y, width=width, color='#e5ae38', label='JavaScrip
# Assign X-label and Y-label respectively
[Link]("Ages")
[Link]("Median Salary (USD)")
[Link](ticks=x_indexes, labels=ages_x)
# Give title to plot
[Link]("Median Salary (USD) by Age")
[Link]()
plt.tight_layout()
[Link]()
[Link] Page 2 of 7
[Link] - Colab 26/05/24, 4:34 PM
The [Link]() function in Matplotlib is used to customize the tick locations and labels on
the x-axis of a plot. Here's an explanation of the parameters:
ticks: This parameter speciMes the locations on the x-axis where you want to place the ticks.
It takes a list of values indicating the positions of the ticks. In your example, x_indexes likely
contains the positions where you want to place ticks on the x-axis.
labels: This parameter is used to provide custom labels for the ticks. It takes a list of labels
corresponding to the tick positions speciMed in the ticks parameter. In your example, ages_x
likely contains the labels that you want to display at each tick position.
import csv
from collections import Counter
with open("/content/matplotlib_2.csv") as csv_file:
csv_reader = [Link](csv_file)
language_counter = Counter()
for row in csv_reader:
language_counter.update(row['LanguagesWorkedWith'].split(';'))
languages = []
popularity = []
for item in language_counter.most_common(15):
[Link](item[0])
[Link](item[1])
# print(languages)
# print(popularity)
[Link]()
[Link]()
# [Link](languages, popularity)
# Assign X-label and Y-label respectively
# [Link]("Programming Languages")
# [Link]("Number of People Who Use")
# bar is not readable so changing to barh
[Link](languages, popularity)
[Link] Page 3 of 7
[Link] - Colab 26/05/24, 4:34 PM
[Link]("Number of People Who Use")
# Give title to plot
[Link]("Most Popular Languages")
[Link]()
plt.tight_layout()
[Link]()
WARNING:[Link]:No artists with labels found to put in legend. Note
import pandas as pd
data = pd.read_csv("/content/matplotlib_2.csv")
ids = data['Responder_id']
lang_responses = data['LanguagesWorkedWith']
for response in lang_responses:
language_counter.update([Link](';'))
languages = []
popularity = []
[Link] Page 4 of 7
[Link] - Colab 26/05/24, 4:34 PM
for item in language_counter.most_common(15):
[Link](item[0])
[Link](item[1])
# print(languages)
# print(popularity)
[Link]()
[Link]()
# [Link](languages, popularity)
# Assign X-label and Y-label respectively
# [Link]("Programming Languages")
# [Link]("Number of People Who Use")
# bar is not readable so changing to barh
[Link](languages, popularity)
[Link]("Number of People Who Use")
# Give title to plot
[Link]("Most Popular Languages")
[Link]()
plt.tight_layout()
[Link]()
[Link] Page 5 of 7
[Link] - Colab 26/05/24, 4:34 PM
WARNING:[Link]:No artists with labels found to put in legend. Note
Start coding or generate with AI.
[Link] Page 6 of 7
[Link] - Colab 26/05/24, 4:34 PM
[Link] Page 7 of 7