Skip to content

Commit

Permalink
update
Browse files Browse the repository at this point in the history
  • Loading branch information
blaylockbk committed Oct 22, 2024
1 parent 74e9971 commit 464e925
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 31 deletions.
Binary file added docs/images/image-11.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
45 changes: 45 additions & 0 deletions docs/matplotlib-dates.md
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"))
```
![alt text](images/image-11.png)

## Dates and colorbars

Use Dates on Colorbar Ticks
https://github.com/matplotlib/matplotlib/issues/17447#issuecomment-630885219
31 changes: 0 additions & 31 deletions docs/matplotlib.md
Original file line number Diff line number Diff line change
Expand Up @@ -64,38 +64,7 @@ plt.rcParams["axes.axisbelow"] = True
plt.rcParams['svg.fonttype'] = 'none'
```

## Dates

```python
import matplotlib.dates as mdates
formatter = mdates.DateFormatter('%Y-%m-%d %H:%M:%S')
ax.xaxis.set_major_formatter(formatter)
```

```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)))
```

Use Dates on Colorbar Ticks
https://github.com/matplotlib/matplotlib/issues/17447#issuecomment-630885219

Set date autoformatter:

```python
plt.rcParams['date.autoformatter.day'] = '%b %d\n%H:%M'
plt.rcParams['date.autoformatter.hour'] = '%b %d\n%H:%M'
```

Set date ticks

```python
from matplotlib.dates import HourLocator, DateFormatter
plt.plot(pd.date_range('2017-01-01', '2017-01-02', freq='h'), range(25))
plt.gca().xaxis.set_major_locator(HourLocator(byhour=range(0,24,6)))
plt.gca().xaxis.set_major_formatter(DateFormatter('%d %b %Y\n%H:%M\n%A'))
```

## Latex Strings

Expand Down

0 comments on commit 464e925

Please sign in to comment.