For code/output blocks: Use ``` (aka backtick or grave accent) in a single line before and after the block. See: http://commonmark.org/help/

Basic Plotting - No X Axis



  • Hi fellow backtraders!
    I have just started familiarizing myself with Backtrader. I have a newbie question for you:
    Using the examples in the Quickstart guide I got to the section on plotting.
    https://www.backtrader.com/docu/quickstart/quickstart/#visual-inspection-plotting
    I copied the code exactly and got an identical plot except the x axis (date) is not showing at all. The cursor gives the right dates but there is no text on the axis. What have I forgotten?!
    Thanks
    (PS: Also, is there a place in Backtrader Community for newbies like me to look at first to find the usual gotchas.)



  • I just wanted to ask the same thing. Good to know I'm not alone!


  • administrators

    The x-axis is there (luckily, because if not everything would be displayed on a singularity rim and we should fear a potential earth implosion into such an event) but the x-ticks (i.e: timestamps in this case) are not displayed in the latest latest version of matplotlib (currently 3.1.1)

    The previous stable version 3.0.3 and the last LTS version 2.2.4 do display the x-ticks.

    pip install --force matplotlib==YOUR-PREFERRED-WORKING-VERSION
    


  • @backtrader Thanks for the rapid reply - it works! Life is good. The universe is back in equilibrium



  • @backtrader Awesome, that fixed it!



  • Hi, i need some help please. I tried to install matplotlib as you say but now i cant run the plot. i tried to change versions, reinstall anoaconda but now always have the same error and i cant show the plots as always. It give me this error:


    TypeError Traceback (most recent call last)
    <ipython-input-8-cf679b847698> in <module>
    1 # cerebro.plot(start=datetime.date(2005, 7, 1), end=datetime.date(2006, 1, 31))
    2
    ----> 3 fig = cerebro.plot(style='candle', numfigs=1, barup ='gold', bardown ='darkgoldenrod', valuetags=False, rowsmajor=5, rowsminor=2, plotdist=0.1)[0][0]
    4 fig.savefig('example.png', dpi=400)
    5 #figure = cerebro.plot(style ='candlebars')[0][0]

    ~\Anaconda3\lib\site-packages\backtrader\cerebro.py in plot(self, plotter, numfigs, iplot, start, end, width, height, dpi, tight, use, **kwargs)
    972
    973 if not plotter:
    --> 974 from . import plot
    975 if self.p.oldsync:
    976 plotter = plot.Plot_OldSync(**kwargs)

    ~\Anaconda3\lib\site-packages\backtrader\plot_init_.py in <module>
    31
    32
    ---> 33 from .plot import Plot, Plot_OldSync
    34 from .scheme import PlotScheme

    ~\Anaconda3\lib\site-packages\backtrader\plot\plot.py in <module>
    33 import numpy as np # guaranteed by matplotlib
    34 import matplotlib.dates as mdates
    ---> 35 import matplotlib.font_manager as mfontmgr
    36 import matplotlib.legend as mlegend
    37 import matplotlib.ticker as mticker

    ~\AppData\Roaming\Python\Python37\site-packages\matplotlib\font_manager.py in <module>
    46
    47 import matplotlib as mpl
    ---> 48 from matplotlib import afm, cbook, ft2font, rcParams, get_cachedir
    49 from matplotlib.fontconfig_pattern import (
    50 parse_fontconfig_pattern, generate_fontconfig_pattern)

    ~\AppData\Roaming\Python\Python37\site-packages\matplotlib\afm.py in <module>
    358
    359
    --> 360 @deprecated("3.0", "Use the class AFM instead.")
    361 def parse_afm(fh):
    362 return _parse_afm(fh)

    TypeError: deprecated() takes 1 positional argument but 2 were given


Log in to reply
 

});