-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
74e9971
commit 464e925
Showing
3 changed files
with
45 additions
and
31 deletions.
There are no files selected for viewing
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
# Matplotlib: Dates | ||
|
||
## Date axis ticks label format | ||
|
||
```python | ||
import matplotlib.dates as mdates | ||
|
||
formatter = mdates.DateFormatter('%Y-%m-%d %H:%M:%S') | ||
ax.xaxis.set_major_formatter(formatter) | ||
``` | ||
|
||
### Set date autoformatter: | ||
|
||
```python | ||
plt.rcParams['date.autoformatter.day'] = '%b %d\n%H:%M' | ||
plt.rcParams['date.autoformatter.hour'] = '%b %d\n%H:%M' | ||
``` | ||
|
||
## Date axis tick location | ||
|
||
```python | ||
import matplotlib.dates as mdates | ||
ax.xaxis.set_major_locator(mdates.HourLocator(range(0, 24, 3))) | ||
ax.xaxis.set_minor_locator(mdates.HourLocator(range(0, 24, 1))) | ||
``` | ||
|
||
## Tick format and location | ||
|
||
```python | ||
import pandas as pd | ||
from matplotlib.dates import HourLocator, DateFormatter | ||
|
||
x = pd.date_range("2017-01-01", "2017-01-02", freq="h") | ||
y = range(len(x)) | ||
plt.plot(x, y, marker=".") | ||
plt.gca().xaxis.set_major_locator(HourLocator(byhour=range(0, 24, 6))) | ||
plt.gca().xaxis.set_minor_locator(HourLocator(byhour=range(0, 24, 1))) | ||
plt.gca().xaxis.set_major_formatter(DateFormatter("%d %b %Y\n%H:%M\n%A")) | ||
``` | ||
 | ||
|
||
## Dates and colorbars | ||
|
||
Use Dates on Colorbar Ticks | ||
https://github.com/matplotlib/matplotlib/issues/17447#issuecomment-630885219 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters