dual line plot done

pull/354/head
Jasleen Sondhi 3 years ago committed by GitHub
parent 85f4683f2e
commit 786b1131b4
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -134,22 +134,17 @@ For this dataset, nothing particularly stands out with regards to the number of
## Dual-line Plots ## Dual-line Plots
Try a multiline plot by superimposing two lineplots on top of each other, using Seaborn's 'despine' to remove their top and right spines, and using `ax.twinx` [derived from Matplotlib](https://matplotlib.org/stable/api/_as_gen/matplotlib.axes.Axes.twinx.html). Twinx allows a chart to share the x axis and display two y axes. So, display the yield per colony and number of colonies, superimposed: Try a multiline plot by superimposing two lineplots on top of each other, using R's `par` and `plot` function. We will be plotting the year in the x axis and display two y axes. So, display the yield per colony and number of colonies, superimposed:
```python
fig, ax = plt.subplots(figsize=(12,6)) ```r
lineplot = sns.lineplot(x=honey['year'], y=honey['numcol'], data=honey, par(mar = c(5, 4, 4, 4) + 0.3)
label = 'Number of bee colonies', legend=False) plot(honey$year, honey$numcol, pch = 16, col = 2,type="l")
sns.despine() par(new = TRUE)
plt.ylabel('# colonies') plot(honey$year, honey$yieldpercol, pch = 17, col = 3,
plt.title('Honey Production Year over Year'); axes = FALSE, xlab = "", ylab = "",type="l")
axis(side = 4, at = pretty(range(y2)))
ax2 = ax.twinx() mtext("colony yield", side = 4, line = 3)
lineplot2 = sns.lineplot(x=honey['year'], y=honey['yieldpercol'], ax=ax2, color="r",
label ='Yield per colony', legend=False)
sns.despine(right=False)
plt.ylabel('colony yield')
ax.figure.legend();
``` ```
![superimposed plots](images/dual-line.png) ![superimposed plots](images/dual-line.png)

Loading…
Cancel
Save