Skip to content

Commit 6244234

Browse files
authored
Merge pull request #94 from chennesy/removing-matplotlib
removing matplot explicit use
2 parents 594190d + 4df4b97 commit 6244234

1 file changed

Lines changed: 18 additions & 22 deletions

File tree

episodes/data-visualisation.md

Lines changed: 18 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -177,46 +177,42 @@ The drop from 2012 through part of 2014 corresponds to the reconstruction period
177177
::::::::::::::::::::::::::::::::::::::::::::::::
178178
::::::::::::::::::::::::::::::::::::::::::::::::
179179

180-
## Use Matplotlib for more detailed charts
180+
## Use Pandas for More Detailed Charts
181181

182-
What if we want to alter the axis labels and the title of the graph. In order to do that, we need to first import `matplotlib`, an extensive plotting package in Python that lets us alter all aspects of a graph.
183-
184-
- We can pass parameters to Matplotlib's `.plot()` function to assign a plot title, to declare a figsize - which accepts a width and height in inches - and to change the color of the line.
185-
- Next we'll add text labels for the x and y axis using `.xlabel()` and `.ylabel`.
186-
- Finally, we need a separate function `.show()` to display the plot using Matplotlib.
182+
What if we want to alter the axis labels and the title of the graph? Pandas' built-in plotting functions, which are backended by Matplotlib, allow us to customize various aspects of a plot without needing to import Matplotlib directly.
187183

184+
- We can pass parameters to Pandas' `.plot()` function to add a plot title, specify a figure size, and change the color of the line.
185+
- Additionally, we can directly set the x and y axis labels within the `.plot()` function.
188186

189187
``` python
190-
# the plotting package pandas is using under the hood to `plot()`
191-
import matplotlib.pyplot as plt
192-
193-
albany['circulation'].plot(title='Circulation Count Over Time', figsize=(10, 5), color='blue')
194-
# Adding labels and showing the plot
195-
plt.xlabel('Date')
196-
plt.ylabel('Circulation Count')
197-
plt.show()
188+
albany['circulation'].plot(title='Circulation Count Over Time',
189+
figsize=(10, 5),
190+
color='blue',
191+
xlabel='Date',
192+
ylabel='Circulation Count')
198193
```
199194

200195
![](fig/albany-circ-labeling-5.png){alt="Line plot of the Albany Park branch circulation with matplotlib styles applied."}
201196

202-
### Changing plot types with Matplotlib
197+
### Changing plot types
203198

204199
What if we want to use a different plot type for this graphic? To do so, we can change the `kind` parameters in our `.plot()` function.
205200

206201
``` python
207-
albany['circulation'].plot(kind='area', title='Circulation Count Area Plot at Albany Park', alpha=0.5)
208-
plt.xlabel('Date')
209-
plt.ylabel('Circulation Count')
210-
plt.show()
202+
albany['circulation'].plot(kind='area',
203+
title='Circulation Count Area Plot at Albany Park', alpha=0.5,
204+
xlabel='Date',
205+
ylabel='Circulation Count')
211206
```
207+
212208
![](fig/albany-circ-area-7.png){alt="Area plot of the Albany Park branch circulation."}
213209

214210
We can also look at our circulation data as a histogram.
215211

216212
``` python
217-
albany['circulation'].plot(kind='hist', bins=20, title='Distribution of Circulation Counts at Albany Park')
218-
plt.xlabel('Circulation Count')
219-
plt.show()
213+
albany['circulation'].plot(kind='hist', bins=20,
214+
title='Distribution of Circulation Counts at Albany Park',
215+
xlabel='Circulation Count')
220216
```
221217

222218
![](fig/albany-circ-hist-9.png){alt="histogram of the Albany branch circulation."}

0 commit comments

Comments
 (0)