Skip to content

Commit 49139b5

Browse files
Merge pull request #13 from DanielGoldfarb/master
Implement `savefig` to save plot to file.
2 parents 417229c + 75dbc86 commit 49139b5

File tree

8 files changed

+292
-10
lines changed

8 files changed

+292
-10
lines changed

.github/ISSUE_TEMPLATE/ask-a-question.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
name: Ask a Question
33
about: Question about usage, project priorities, or anything else related to mplfinance.
44
title: ''
5-
labels: ''
5+
labels: 'question'
66
assignees: ''
77

88
---

.github/ISSUE_TEMPLATE/bug_report.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
---
22
name: Bug report
33
about: Create a report to help us improve
4-
title: ''
5-
labels: ''
4+
title: 'Bug Report:'
5+
labels: 'bug'
66
assignees: ''
77

88
---

.github/ISSUE_TEMPLATE/feature_request.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
---
22
name: Feature request
33
about: Suggest an idea for this project
4-
title: ''
5-
labels: ''
4+
title: 'Feature Reuest:'
5+
labels: 'enhancement'
66
assignees: ''
77

88
---

.github/ISSUE_TEMPLATE/feedback.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
---
22
name: Feedback
33
about: What do you think of mplfinance? Pros? Cons? Thoughts?
4-
title: ''
5-
labels: ''
4+
title: 'Comment:'
5+
labels: 'feedback'
66
assignees: ''
77

88
---

README.md

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
- **[The New API](https://github.com/matplotlib/mplfinance#newapi)**
1717
- **[Basic Usage](https://github.com/matplotlib/mplfinance#usage)**
1818
- **[Adding Custom Data to Ohlcv Plots](https://github.com/matplotlib/mplfinance/blob/master/examples/addplot.ipynb)**
19+
- **[Saving the Plot to a File](https://github.com/matplotlib/mplfinance/blob/master/examples/savefig.ipynb)**
1920
- Customizing the Appearance of Plots (presently in development)
2021
- Technical Studies (presently in development)
2122
- **[Latest Release Info](https://github.com/matplotlib/mplfinance#release)**
@@ -535,7 +536,7 @@ For more examples of using mplfinance, please see the jupyter notebooks in the `
535536

536537
| Version | Description | Release Date |
537538
|----------|--------------|----------------|
538-
| 0.12.x | Ability plot arbitrary user data (in addition to basic OHLCV data).<br> - both line and scatter plots available.<br> - optionally plot on either the "main" or "lower" (aka "volume") axis. | 2020-01-09 |
539+
| 0.12.x | Ability to plot arbitrary user data (in addition to basic OHLCV data).<br> - both line and scatter plots available.<br> - optionally plot on either the "main" or "lower" (aka "volume") axis. | 2020-01-09 |
539540
| 0.11.x | Basic Plotting from Pandas DataFrame of OHLC bars and candlesticks.<br> - optional display of volume<br> - optional display of (up to 3 different) moving averages.<br> - old API still available by importing from "mplfinance/original_flavor" | 2019-12-20 |
540541
| 0.10.x | Old mpl-finance API set up as its own package<br> (i.e. removed from the matplotlib package). | 2016-09-08 |
541542

@@ -567,3 +568,5 @@ where `<method>` indicates the method you want to import, for example:
567568
```python
568569
from mplfinance.original_flavor import candlestick_ohlc
569570
```
571+
---
572+

examples/savefig.ipynb

Lines changed: 267 additions & 0 deletions
Large diffs are not rendered by default.

src/mplfinance/_version.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
version_info = (0, 12, 0, 'alpha', 1)
1+
version_info = (0, 12, 0, 'alpha', 2)
22

33
_specifier_ = {'alpha': 'a', 'beta': 'b', 'candidate': 'rc', 'final': ''}
44

src/mplfinance/plotting.py

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,11 @@ def _valid_kwargs_table():
9797
'Implemented' : True,
9898
'Validator' : lambda value: isinstance(value,dict) or (isinstance(value,list) and all([isinstance(d,dict) for d in value])) },
9999

100+
'savefig' : { 'Default' : None,
101+
102+
'Implemented' : True,
103+
'Validator' : lambda value: isinstance(value,dict) or isinstance(value,str) },
104+
100105
}
101106
# Check that we didn't make a typo in any of the things above:
102107
# that should otherwise be the same for all kwags:
@@ -355,7 +360,14 @@ def plot( data, **kwargs ):
355360
vol_label = 'Volume x '+str(offset)
356361
ax2.set_ylabel(vol_label,size='x-large',weight='semibold')
357362

358-
plt.show()
363+
if config['savefig'] is not None:
364+
save = config['savefig']
365+
if isinstance(save,dict):
366+
plt.savefig(**save)
367+
else:
368+
plt.savefig(save)
369+
else:
370+
plt.show()
359371

360372
def _valid_addplot_kwargs_table():
361373

0 commit comments

Comments
 (0)