Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Sharing X Axis in Sub plots
#1
Hello community

After a LOT of fighting and watching youtube tutorials i have been able to achieve my goal of creating a figure window, with a unique name and 4 subplots.

The method i used was add_subplot because i understand the code better rather than unpacking Tuples method i.e. fig, ...

The last bit i am trying to do is share my x axis and after a lot of playing around i.e. trying to insert the code sharex="Cols" or sharex = True i have had no success.

My complete code is as follows:-

import pandas
import numpy
from matplotlib import pyplot

x = numpy.linspace(0, 2*numpy.pi, 400)
y = numpy.sin(x**2)
yy = numpy.sin(x**2+3)

My_Figure_Window = pyplot.figure("Title Of Figure Window") 
pyplot.style.use("ggplot")
My_Figure_Window.suptitle("Main Title")

Sub_Plot_Rows = 4 
Sub_Plot_Cols = 1 

Wall = My_Figure_Window.add_subplot(Sub_Plot_Rows, Sub_Plot_Cols, 1)
Wall.plot(x, y, color="r", label='Line 1')
Wall.plot(x, yy, color="b", label='Line 2')
pyplot.ylabel("Ylabel")
Wall.get_legend_handles_labels()
pyplot.legend()
pyplot.show()

Sidewalk = My_Figure_Window.add_subplot(Sub_Plot_Rows, Sub_Plot_Cols, 2) 
Sidewalk.plot(x, y, label='Line 3')
Sidewalk.plot(x, yy, label='Line 4')
pyplot.ylabel("Ylabel")
Sidewalk.get_legend_handles_labels()
pyplot.legend()
pyplot.show()

HeadWall = My_Figure_Window.add_subplot(Sub_Plot_Rows, Sub_Plot_Cols, 3) 
HeadWall.plot(x, y, label='Line 5')
HeadWall.plot(x, yy, label='Line 6')
pyplot.ylabel("Ylabel")
HeadWall.get_legend_handles_labels()
pyplot.legend()
pyplot.show()

SideTank = My_Figure_Window.add_subplot(Sub_Plot_Rows, Sub_Plot_Cols, 4) 
SideTank.plot(x, y, label='Line 7')
SideTank.plot(x, yy, label='Line 8')
pyplot.ylabel("Ylabel")
SideTank.get_legend_handles_labels()
pyplot.legend()
pyplot.show()
Can anyone just point me in the right direction as to where / how i can share my x axis for all these subplots????

On a side note i have realised that the code pyplot.show() does not have any affect yet everyone includes it?

Thank you.
Reply
#2
I don't understand what you mean by "share my x axis". Are you trying to figure out how to have multiple plots in one window? All you need to do is get rid of all but the last "show()" commands
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Best way to secure API key when sharing quarinteen 2 290 Jan-19-2024, 04:46 PM
Last Post: deanhystad
  Multiple Plots in Spyder PythonAndMe2023 0 816 Feb-03-2023, 07:00 PM
Last Post: PythonAndMe2023
  How to install modules for 2.7 (or sharing from 3.8)) Persisto 2 2,374 Dec-31-2021, 02:33 PM
Last Post: Persisto
  Subplot - Plotting 4 plots on the same row Menthix 1 1,392 Nov-07-2021, 09:03 PM
Last Post: deanhystad
  Sample labels from excel file in order to put them on x-axis and y-axis of a plot hobbyist 11 4,232 Sep-14-2021, 08:29 AM
Last Post: hobbyist
  multiprocessing and sharing object cyrduf 0 2,011 Feb-02-2021, 08:16 PM
Last Post: cyrduf
  sharing variables between two processes Kiyoshi767 1 1,848 Nov-07-2020, 04:00 AM
Last Post: ndc85430
  Creating Plots & Sharing X Axis JoeDainton123 2 1,849 Oct-05-2020, 04:33 PM
Last Post: JoeDainton123
  Sharing my code emirasal 2 1,998 Oct-04-2020, 02:21 PM
Last Post: emirasal
  Difference Between Figure Axis and Sub Plot Axis in MatplotLib JoeDainton123 2 2,426 Aug-21-2020, 10:17 PM
Last Post: JoeDainton123

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020