Matplotlib Tutorial 10 – basic customizations, rotating labels




[ad_1]

In this Matplotlib tutorial, we’re going to be talking about some of the possible customizations to graphs. In order to start modifying the subplots, we have to define them. We will talk about them soon, but there are two major ways to define subplots, and to structure them. For now, we’ll just use one of them, but we will be explaining them shortly.

sample code: http://pythonprogramming.net
http://hkinsley.com
https://twitter.com/sentdex
http://sentdex.com
http://seaofbtc.com

Source


[ad_2]

Comment List

  • sentdex
    December 30, 2020

    Oh my god that line size 5 was so uncomfortable, I need some unsee juice now XD

  • sentdex
    December 30, 2020

    puedes traducirlo

  • sentdex
    December 30, 2020

    Is there a way to automatically change the subplot adjust? I wrote a program to draw an ellipse if you input the verticies. While it works, when it is horizontal, it looks correct, but when it is vertical, it still looks horizontal even when the vertical values are bigger than the horizontal values. I can adjust the subplots manually to make it look correct, but I would prefer it to happen automatically.

  • sentdex
    December 30, 2020

    It's good , but if take other example(data) ..

  • sentdex
    December 30, 2020

    These wheels came off this series of tutorials when the last lesson's API was changed but the code was not. I am giving up at this point and stopping watching this series. Nothing personal but the tutorial is a mess from the last video on….

  • sentdex
    December 30, 2020

    I know you can save it as a .png file. Is there a way to save it as some time of interactive file where the user can run their mouse over the graph to see the coordinates?

  • sentdex
    December 30, 2020

    What is the purpose of making the 'fig' variable in this tutorial?

  • sentdex
    December 30, 2020

    Can you give me a google api for another stock company

  • sentdex
    December 30, 2020

    —————————————————————————
    KeyError Traceback (most recent call last)
    ~Anacondanavlibsite-packagespandascoreindexesbase.py in get_loc(self, key, method, tolerance)
    3062 try:
    -> 3063 return self._engine.get_loc(key)
    3064 except KeyError:

    pandas_libsindex.pyx in pandas._libs.index.IndexEngine.get_loc()

    pandas_libsindex.pyx in pandas._libs.index.IndexEngine.get_loc()

    pandas_libshashtable_class_helper.pxi in pandas._libs.hashtable.PyObjectHashTable.get_item()

    pandas_libshashtable_class_helper.pxi in pandas._libs.hashtable.PyObjectHashTable.get_item()

    KeyError: 'Date'

    During handling of the above exception, another exception occurred:

    KeyError Traceback (most recent call last)
    <ipython-input-23-295e932dc526> in <module>()
    38 plt.show()
    39
    —> 40 graph_date('TSLA')

    <ipython-input-23-295e932dc526> in graph_date(stock)
    29
    30 df_stocks = pd.DataFrame(df_list, columns=fields, index=range(1,len(df_list)+1))
    —> 31 print(df_stocks['Date'])
    32 df_stocks['Date'] = map(ch, df_stocks['Date'])
    33 print(df_stocks['Date'])

    ~Anacondanavlibsite-packagespandascoreframe.py in __getitem__(self, key)
    2683 return self._getitem_multilevel(key)
    2684 else:
    -> 2685 return self._getitem_column(key)
    2686
    2687 def _getitem_column(self, key):

    ~Anacondanavlibsite-packagespandascoreframe.py in _getitem_column(self, key)
    2690 # get column
    2691 if self.columns.is_unique:
    -> 2692 return self._get_item_cache(key)
    2693
    2694 # duplicate columns & possible reduce dimensionality

    ~Anacondanavlibsite-packagespandascoregeneric.py in _get_item_cache(self, item)
    2484 res = cache.get(item)
    2485 if res is None:
    -> 2486 values = self._data.get(item)
    2487 res = self._box_item_values(item, values)
    2488 cache[item] = res

    ~Anacondanavlibsite-packagespandascoreinternals.py in get(self, item, fastpath)
    4113
    4114 if not isna(item):
    -> 4115 loc = self.items.get_loc(item)
    4116 else:
    4117 indexer = np.arange(len(self.items))[isna(self.items)]

    ~Anacondanavlibsite-packagespandascoreindexesbase.py in get_loc(self, key, method, tolerance)
    3063 return self._engine.get_loc(key)
    3064 except KeyError:
    -> 3065 return self._engine.get_loc(self._maybe_cast_indexer(key))
    3066
    3067 indexer = self.get_indexer([key], method=method, tolerance=tolerance)

    pandas_libsindex.pyx in pandas._libs.index.IndexEngine.get_loc()

    pandas_libsindex.pyx in pandas._libs.index.IndexEngine.get_loc()

    pandas_libshashtable_class_helper.pxi in pandas._libs.hashtable.PyObjectHashTable.get_item()

    pandas_libshashtable_class_helper.pxi in pandas._libs.hashtable.PyObjectHashTable.get_item()

    KeyError: 'Date'

  • sentdex
    December 30, 2020

    you lost me real fast on these matplotlib tutorials… gotta check out other channels now….

  • sentdex
    December 30, 2020

    This code works with current version of matplotlib (AD 2018).

    def bytespdate2num(fmt, encoding='utf-8'):
    strconverter = mdates.strpdate2num(fmt)
    def bytesconverter(b):
    s = b.decode(encoding)
    return strconverter(s)
    return bytesconverter

    def graph_data():

    fig = plt.figure()
    ax_1 = plt.subplot2grid((1, 1), # Plot grid
    (0, 0)) # Starting point of plot

    stock_price_url = 'https://pythonprogramming.net/yahoo_finance_replacement&#39;
    source_code = urllib.request.urlopen(stock_price_url).read().decode()

    stock_data = []
    split_source = source_code.split('n')

    for line in split_source[1:]:
    stock_data.append(line)

    # closep = close price. Nazwy pozostałych zmiennych rozwija się
    # analogicznie.
    # adjustedp = adjusted close price
    date, closep, highp, lowp, openp, adjustedp, volume
    = np.loadtxt(stock_data, delimiter=',', unpack=True,
    # %Y = full year: 2015
    # %y = partial year: 15
    # %m = number of month
    # %d = number of day
    # %H = hours
    # %M = minutes
    # %S = seconds
    converters={0: bytespdate2num('%Y-%m-%d')})

    ax_1.plot_date(date, closep, '-', label='Price')

    for label in ax_1.xaxis.get_ticklabels():
    label.set_rotation(45)

    ax_1.grid(True, color='g', linestyle='–')
    # linewidth=5) # Stupid, but you can do it

    ax_1.set_xlabel('date')
    ax_1.set_ylabel('price')

    ax_1.set_title('Price of stocks')
    ax_1.legend()
    fig.subplots_adjust(left=0.1, bottom=0.20, right=0.94, top=0.95,
    wspace=0.2, hspace=0)
    fig.show()

    graph_data()

  • sentdex
    December 30, 2020

    This my by wrongheaded hairsplitting. I think this video title should be "Matplotlib Tutorial 10 – Basic customizations, rotating labels".

  • sentdex
    December 30, 2020

    Sentdex, how about explicitly using subplot(). Have a look:

    plt.subplot(311)
    plt.plot([1,2,3], [2,4,6], 'o']

    plt.subplot(312)
    plt.plot(range(12))

    plt.subplot(313)
    plt.plot([1,2,3], [2,4,6], 'D']

    plt.show()

    It seems a lot easier to follow, but let me know if I am missing a point or something. Your tutorials are very helpful since I am a novice.

    Question: Why do you use figure()? Even the documentation on MATPLOTLIB is very vague.

  • sentdex
    December 30, 2020

    Hey Sentdex. I got to the "getting data from the internet for matplotlib" video. But that URL is dead. I now see that lots of the following vids are based on that data. Could you provide a solution to getting new data somehow so that it is possible to finish your matplotlib tutorial. thanks! love the content btw

  • sentdex
    December 30, 2020

    it is just great!

  • sentdex
    December 30, 2020

    I like your tutorial so much! Easy to follow man! Hope you stay with us for longer!

  • sentdex
    December 30, 2020

    Maybe a question, if there would be no matplotlib, how would you solve the way to paint the dots and lines on the screen? Is it possible or only much more complicated? And are this addons coded in python too, or this are other languages?

  • sentdex
    December 30, 2020

    Awesome!!!! Its fun to follow your code and get the same results, even as a total beginner 🙂

  • sentdex
    December 30, 2020

    Really appreciate all of these vids man! Got a quick question about customizing the numbers on the Y axis, I'm working on one of your other series for fundamental investing and all of the digits convert to decimals with an exponent. Is there a way to get matplotlib to show the entire number instead of the exponential form?

  • sentdex
    December 30, 2020

    can you explain the tutorial 8 &9 in different way ?

  • sentdex
    December 30, 2020

    Better solution for rotation is just:
    plt.xticks(rotation=45)

Write a comment