Get the App
SLTechnology News&Howtos  ›  Development  › 

How to use matplotlib to draw subgraphs and share y axes

Shulou Source: shulou.com Published: 2022-06-01 12:04:25 10月03日 Update

This article mainly introduces how to use matplotlib to draw subimages and share the relevant knowledge of the y-axis, the content is detailed and easy to understand, the operation is simple and fast, and has a certain reference value. I believe you will gain something after reading this article on how to use matplotlib to draw subimages and share the y-axis. Let's take a look.

What does the data look like?

There are two data segments, the first of which is of type DataFrame and the second of which is of type ndarray. Each data has three columns. I want to draw a broken line subgraph of 1: 3. The nth column of the first data and the nth column of the second data are drawn on a subgraph. Let's take a look at what the two data look like (just look at the first five lines for display convenience).

In [1]: testing_set.head () # DataFrame type Out [1]: Open High Low 0 778.81 789.63 775.80 1 788.36 791.34 783.16 2 786.08 794.48 785.02 3 795.26 807.90 792.20 4 806.40 809.97 802.83 # ndarray type In [2]: predicted_stock_price # here just look at the first five lines Out [2]: [[790.6911 796.39215 779.3191] [790.24524 796.0866 778.9673] [789.5737 795.52606 778.3751] [790.1047 796.10864 778.92395] [790.8686 796.94104 779.7281]] implementation process

Note: plt.setp () is used to share y axes

# create canvas fig = plt.figure (figsize = (30jing10), dpi = 80) # subgraph 1ax1 = plt.subplot (131ax1.set_title ('Open Price') ax1.plot (testing_set.values [:, 0], color =' red', label = 'Real Open Price') ax1.plot (predicted_stock_price [:, 0], color =' blue', label = 'Predicted Open Price') plt.setp (ax1.get_xticklabels () Fontsize=6) ax1.legend () # subimage 2ax2 = plt.subplot (132filmshareyshareax1) ax2.set_title ('High Price') ax2.plot (testing_set.values [:, 1], color =' red', label = 'Real High Price') ax2.plot (predicted_stock_price [:, 1], color =' blue', label = 'Predicted High Price') ax2.legend () # subgraph 3ax3 = plt.subplot (133 shareyshareax1) ax3.set_title (' Low Price') ax3.plot (testing_set.values [: 2], color = 'red', label =' Real Low Price') ax3.plot (predicted_stock_price [:, 2], color = 'blue', label =' Predicted Low Price') ax3.legend () plt.show () this is the end of the article on "how to draw subgraphs and share y axes with matplotlib" Thank you for reading! I believe that everyone has a certain understanding of "how to use matplotlib to draw subpictures and share y axes". If you want to learn more, you are welcome to follow the industry information channel.

Tags: Data coordinate axis type knowledge two content article value broken line easy to operate article easy to understand more sample canvas look industry information information channel Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Shulou Technology Docker Huawei OPPO Reno NVidia