Skip to content

Commit 2c88663

Browse files
backend investigations of flashing (see Shlomi Golubev email).
1 parent 28adb59 commit 2c88663

File tree

3 files changed

+110
-13
lines changed

3 files changed

+110
-13
lines changed

Diff for: examples/scratch_pad/find.valid.backends.py

+60
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
from __future__ import print_function, division, absolute_import
2+
from pylab import *
3+
import time
4+
5+
import matplotlib.backends
6+
import matplotlib.pyplot as p
7+
import os.path
8+
9+
10+
def is_backend_module(fname):
11+
"""Identifies if a filename is a matplotlib backend module"""
12+
return fname.startswith('backend_') and fname.endswith('.py')
13+
14+
def backend_fname_formatter(fname):
15+
"""Removes the extension of the given filename, then takes away the leading 'backend_'."""
16+
return os.path.splitext(fname)[0][8:]
17+
18+
# get the directory where the backends live
19+
backends_dir = os.path.dirname(matplotlib.backends.__file__)
20+
21+
# filter all files in that directory to identify all files which provide a backend
22+
backend_fnames = filter(is_backend_module, os.listdir(backends_dir))
23+
24+
backends = [backend_fname_formatter(fname) for fname in backend_fnames]
25+
26+
print("supported backends: \t" + str(backends))
27+
28+
# validate backends
29+
backends_valid = []
30+
for b in backends:
31+
try:
32+
p.switch_backend(b)
33+
backends_valid += [b]
34+
except:
35+
continue
36+
37+
print("valid backends: \t" + str(backends_valid))
38+
39+
40+
# try backends performance
41+
for b in backends_valid:
42+
43+
ion()
44+
try:
45+
p.switch_backend(b)
46+
47+
48+
clf()
49+
tstart = time.time() # for profiling
50+
x = arange(0,2*pi,0.01) # x-array
51+
line, = plot(x,sin(x))
52+
for i in arange(1,200):
53+
line.set_ydata(sin(x+i/10.0)) # update the data
54+
draw() # redraw the canvas
55+
56+
print(b + ' FPS: \t' , 200/(time.time()-tstart))
57+
ioff()
58+
59+
except:
60+
print(b + " error :(")

Diff for: examples/scratch_pad/run.valid.ibackends.py

+34
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
import matplotlib.pyplot as plt
2+
import matplotlib as mpl
3+
from pylab import *
4+
5+
## ==================================================================================
6+
## supported backends: ['ps', 'webagg', 'qt4agg', 'agg', 'wx', 'svg', 'qt5agg',
7+
## 'template', 'gtk3cairo', 'pdf', 'qt5cairo', 'macosx',
8+
## 'qt4', 'gtk3agg', 'nbagg', 'webagg_core', 'wxcairo',
9+
## 'qt5', 'gtk3', 'mixed', 'tkagg', 'qt4cairo', 'tkcairo',
10+
## 'wxagg', 'pgf', 'cairo']
11+
## valid backends: ['ps', 'webagg', 'agg', 'svg', 'template', 'pdf', 'nbagg',
12+
## 'tkagg', 'pgf']
13+
## ps FPS: 1823.8522934563061
14+
## webagg FPS: 7169.995555403603
15+
## agg FPS: 20.852366968595575
16+
## svg FPS: 3809.921063866508
17+
## template FPS: 23.202661861618655
18+
## pdf FPS: 2901.3876399053693
19+
## <IPython.core.display.Javascript object>
20+
## <IPython.core.display.HTML object>
21+
## nbagg error :(
22+
## tkagg FPS: 2901.929636420244
23+
## pgf FPS: 5311.09436829276
24+
## ==================================================================================
25+
26+
x = arange(0,2*pi,0.01)
27+
28+
#for b in ['tkagg','webagg','nbagg']:
29+
#for b in ['tkagg','nbagg']:
30+
for b in ['tkagg','Qt5Agg']:
31+
mpl.use(b)
32+
print('Backend: ',plt.get_backend())
33+
plt.plot(x,sin(x))
34+
plt.show()

Diff for: src/mplfinance/plotting.py

+16-13
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
import matplotlib.colors as mcolors
44
import matplotlib.axes as mpl_axes
55
import matplotlib.figure as mpl_fig
6+
import matplotlib.ticker as mtk
67
import pandas as pd
78
import numpy as np
89
import copy
@@ -471,6 +472,13 @@ def plot( data, **kwargs ):
471472
if collection is not None:
472473
axA1.add_collection(collection)
473474

475+
xrotation = config['xrotation']
476+
if not external_axes_mode:
477+
_set_ticks_on_bottom_panel_only(panels,formatter,rotation=xrotation)
478+
else:
479+
axA1.tick_params(axis='x',rotation=xrotation)
480+
axA1.xaxis.set_major_formatter(formatter)
481+
474482
datalen = len(xdates)
475483
if config['volume']:
476484
vup,vdown = style['marketcolors']['volume'].values()
@@ -488,13 +496,6 @@ def plot( data, **kwargs ):
488496
maxy = 1.1 * np.nanmax(volumes)
489497
volumeAxes.set_ylim( miny, maxy )
490498

491-
xrotation = config['xrotation']
492-
if not external_axes_mode:
493-
_set_ticks_on_bottom_panel_only(panels,formatter,rotation=xrotation)
494-
else:
495-
axA1.tick_params(axis='x',rotation=xrotation)
496-
axA1.xaxis.set_major_formatter(formatter)
497-
498499
addplot = config['addplot']
499500
if addplot is not None and ptype not in VALID_PMOVE_TYPES:
500501
# NOTE: If in external_axes_mode, then all code relating
@@ -609,9 +610,14 @@ def plot( data, **kwargs ):
609610
axA1.set_ylabel(config['ylabel'])
610611

611612
if config['volume']:
612-
volumeAxes.figure.canvas.draw() # This is needed to calculate offset
613-
offset = volumeAxes.yaxis.get_major_formatter().get_offset()
614-
volumeAxes.yaxis.offsetText.set_visible(False)
613+
if external_axes_mode:
614+
volumeAxes.tick_params(axis='x',rotation=xrotation)
615+
volumeAxes.xaxis.set_major_formatter(formatter)
616+
#volumeAxes.figure.canvas.draw() # This is needed to calculate offset
617+
volumeAxes.yaxis.set_major_formatter(mtk.FormatStrFormatter('%.0e'))
618+
#offset = volumeAxes.yaxis.get_major_formatter().get_offset()
619+
#volumeAxes.yaxis.offsetText.set_visible(False)
620+
offset = ''
615621
if len(offset) > 0:
616622
offset = (' x '+offset)
617623
if config['ylabel_lower'] is None:
@@ -621,9 +627,6 @@ def plot( data, **kwargs ):
621627
offset = '\n'+offset
622628
vol_label = config['ylabel_lower'] + offset
623629
volumeAxes.set_ylabel(vol_label)
624-
if external_axes_mode:
625-
volumeAxes.tick_params(axis='x',rotation=xrotation)
626-
volumeAxes.xaxis.set_major_formatter(formatter)
627630

628631
if config['title'] is not None:
629632
if config['tight_layout']:

0 commit comments

Comments
 (0)