Python Forum
plot on the same figure using a for loo with matplotlib
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
plot on the same figure using a for loo with matplotlib
#1
I plot lists' element, which is itself element of a dictionary, in several figure using a for loop
    for ind, item in enumerate(drop_down_var['h']):
        print([item[1:], drop_down_var['h'][ind][1:]])
        x = np.array(item[1:70])
        y = np.array(drop_down_var['h*(Tw-T)'][ind][1:70])
        fig, ax = plt.subplots()
        ax.semilogx(x, y)
        ax.grid(True)
    plt.show()
how can I plot all the figure within the same figure?
Reply
#2
Create the figure before the loop, configured to have the number of sublpots you will need. Now ax will be a list. Configure each ax individually inside the loop as you are doing now.
Reply
#3
thanks. It seems there ia a problem with semilogx

AttributeError: 'numpy.ndarray' object has no attribute 'semilogx'
and by the way, I want all the plot to overlap (plot on the same axis)
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Graphic line plot with matplotlib, text file in pytho khadija 2 1,375 Aug-15-2022, 12:00 PM
Last Post: khadija
  matplotlib, no plot when using Figure ajvperth 2 1,673 Oct-12-2021, 02:29 PM
Last Post: ajvperth
  Matplotlib: How do I convert Dates from Excel to use in Matplotlib JaneTan 1 3,216 Mar-11-2021, 10:52 AM
Last Post: buran
  Python Matplotlib: How do I plot lines with different end point in the same graph? JaneTan 0 1,575 Feb-28-2021, 11:56 AM
Last Post: JaneTan
  How to plot intraday data of several days in one plot mistermister 3 2,896 Dec-15-2020, 07:43 PM
Last Post: deanhystad
  saving only one line of a figure as an image (python matplotlib) nitrochloric 0 2,011 Nov-23-2020, 01:41 PM
Last Post: nitrochloric
  Difference Between Figure Axis and Sub Plot Axis in MatplotLib JoeDainton123 2 2,464 Aug-21-2020, 10:17 PM
Last Post: JoeDainton123
  Understanding The Arguments for matplotlib.pyplot.plot JoeDainton123 0 1,921 Aug-19-2020, 01:19 AM
Last Post: JoeDainton123
  How to plot gantt chart using matplotlib Mekala 1 2,629 Jul-16-2020, 07:21 PM
Last Post: Marbelous
  How can I make a plot representing connection relationship with python matplotlib? Berlintofind 1 1,944 May-08-2020, 09:27 PM
Last Post: jefsummers

Forum Jump:

User Panel Messages

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