Add shaded regions to your plot
When plotting time series data in Python, it is also possible to highlight complete regions of your time series plot. In order to add a shaded region between January 1, 1936 and January 1, 1950, you can use the command:
ax.axvspan('1936-01-01', '1950-01-01', color='red' , alpha=0.5)
Here we specified the overall transparency of the region by using the alpha
argument (where 0
is completely transparent and 1
is full color).
Este ejercicio forma parte del curso
Visualizing Time Series Data in Python
Instrucciones de ejercicio
- Use the
.axvspan()
method to add a vertical red shaded region between the dates of January 1, 1900 and January 1, 1915 with a transparency of0.3
. - Use the
.axhspan()
method to add a horizontal green shaded region between the values of 6 and 8 with a transparency of0.3
.
Ejercicio interactivo práctico
Pruebe este ejercicio completando este código de muestra.
# Plot your the discoveries time series
ax = discoveries.plot(color='blue', fontsize=6)
# Add a vertical red shaded region
ax.____('1900-01-01', ____, color=____, alpha=____)
# Add a horizontal green shaded region
ax.____(6, ____, color=____, alpha=____)
plt.show()