plt.subplots() returns a tuple of figure and subplots, so you should do instead

fig, ax = plt.subplots()
ax.plot(coDF2020LA['Date_Local'],coDF2020LA['Arithmetic_Mean'])
ax.axvspan(date2num(datetime(2020,3,1)), date2num(datetime(2020,5,1)),color="blue", alpha=0.3)
Answer from enzo on Stack Overflow
Discussions

python - AttributeError: 'tuple' object has no attribute - Stack Overflow
I'm a beginner in python. I'm not able to understand what the problem is? def list_benefits(): s1 = "More organized code" s2 = "More readable code" s3 = "Easier code reuse... More on stackoverflow.com
🌐 stackoverflow.com
Issue with matplotlib syntax
However, the program keeps the empty spaces of the subplots. this is not surprising, you still create the same figure, but then you only populate one of the sub-plots Please suggest the correct syntax to chart the graph without using at all the grid and subplot features. I only need to chart one chart from now on. Something like this should work for a single plot: fig, ax = plt.subplots(1, 1, facecolor='#ffffff', figsize=(10, 8), dpi=75) ax.plot(df.rolling_100_correlation,color='blue', label='rolling') plt.legend() plt.show() you probably don't want fig size (10, 8). You can mess with these values to change width and height proportional to text etc, and then you can use dpi to uniformly scale up or down the entire image size More on reddit.com
🌐 r/learnpython
3
1
October 28, 2022
AttributeError: tuple' object has no attribute 'autoscale_None'"
I tried to have histogram that has the same scale in two plots. Porting different Python examples resulted in the same error ERROR: PyError (:PyObject_Call) AttributeError("'tuple' object has no attribute 'autoscale_None'",). More on github.com
🌐 github.com
2
July 8, 2015
AttributeError: 'tuple' object has no attribute 'append'
Tuples in Python are immutable, i.e., they can’t be changed (and therefore appended to) like lists can. That’s why you’re getting the error that you have · It looks like the example code you’re using has become deprecated since plotly 3.0 has switched to representing Figure.data as ... More on community.plotly.com
🌐 community.plotly.com
3
0
July 16, 2018
🌐
LearnDataSci
learndatasci.com › solutions › python-attributeerror-tuple-object-has-no-attribute
Python AttributeError: 'tuple' object has no attribute – LearnDataSci
The underscore conveys to readers of your code that you intend not to use the index value. The error AttributeError: 'tuple' object has no attribute is caused when treating the values within a tuple as named attributes.
🌐
Bobby Hadz
bobbyhadz.com › blog › python-attributeerror-tuple-object-has-no-attribute
AttributeError: 'tuple' object has no attribute X in Python | bobbyhadz
April 8, 2024 - The Python "AttributeError: 'tuple' object has no attribute" occurs when we access an attribute that doesn't exist on a tuple.
🌐
Reddit
reddit.com › r/learnpython › issue with matplotlib syntax
r/learnpython on Reddit: Issue with matplotlib syntax
October 28, 2022 -

I have a program that plots five graphs using the grid and the add-sub plots features. It works fine. From now on, I only need to plot one specific chart. I will never plot the other four. When I add only one chart that I need, the program correctly shows the graph. However, the program keeps the empty spaces of the subplots. See the included working code snippet. Please suggest the correct syntax to chart the graph without using at all the grid and subplot features. I only need to chart one chart from now on. For whatever reason, I tried several versions and could not make them work. Thank you for your help.

The following is the working code with the grid and add_subplots:

from matplotlib.gridspec import GridSpec
fig=plt.figure(figsize=(10,8))
Grid=GridSpec(3,2) 
ax5=fig.add_subplot(Grid[1,:])
ax5.plot(df.rolling_100_correlation,color='blue',
     label='rolling')
plt.show()
🌐
GitHub
github.com › JuliaPy › PyPlot.jl › issues › 142
AttributeError: tuple' object has no attribute 'autoscale_None'" · Issue #142 · JuliaPy/PyPlot.jl
July 8, 2015 - PyPlot.clf() (fig,axes)=PyPlot.subplots(2,1) @pyimport mpl_toolkits.axes_grid1 as axgrid im=axes[1][:hist2d](x,y,100) im=axes[2][:hist2d](x2,y2,100) ax = gca() divider = axgrid.make_axes_locatable(ax) cax = divider[:append_axes]("right", size="5%", pad=0.05) colorbar(im, cax=cax) ERROR: PyError (:PyObject_Call) <type 'exceptions.AttributeError'> AttributeError("'tuple' object has no attribute 'autoscale_None'",)
Author   JuliaPy
🌐
Plotly
community.plotly.com › 📊 plotly python
AttributeError: 'tuple' object has no attribute 'append' - 📊 Plotly Python - Plotly Community Forum
July 16, 2018 - Tuples in Python are immutable, i.e., they can’t be changed (and therefore appended to) like lists can. That’s why you’re getting the error that you have · It looks like the example code you’re using has become deprecated since plotly 3.0 has switched to representing Figure.data as ...
Find elsewhere
🌐
Streamlit
discuss.streamlit.io › using streamlit
Having Problem of Pyplot Feature on Streamlit - Using Streamlit - Streamlit
August 21, 2022 - Hello @blackary I tried subplot instead of plt.figure (…) for pie and bar chart like this and the other codes same as above: Example: plot0=plt.subplots() and st.pyplot(plot0) but I got this error: AttributeError:tuple object has no attribute savefig · Here’s how you can use st.pyplot() ...
🌐
GitHub
github.com › matplotlib › matplotlib › issues › 25560
[Bug]: legend for Poly3dCollection fails · Issue #25560 · matplotlib/matplotlib
March 27, 2023 - --> 789 legend_handle._facecolor = first_color(orig_handle.get_facecolor()) 790 legend_handle._edgecolor = first_color(orig_handle.get_edgecolor()) 791 legend_handle._original_facecolor = orig_handle._original_facecolor File /opt/homebrew/lib/python3.11/site-packages/matplotlib/legend_handler.py:777, in HandlerPolyCollection._update_prop.<locals>.first_color(colors) 774 def first_color(colors): --> 775 if colors.size == 0: 776 return (0, 0, 0, 0) 779 return tuple(colors[0]) AttributeError: 'tuple' object has no attribute 'size' Supposed to insert a legend.
Author   matplotlib
🌐
Matplotlib
matplotlib.org › 1.5.3 › api › axes_api.html
axes — Matplotlib 1.5.3 documentation
The default value is 0 (no overlap). ... The center frequency of x (defaults to 0), which offsets the x extents of the plot to reflect the frequency range used when a signal is acquired and then filtered and downsampled to baseband. ... Whether to include the line object plotted in the returned values. Default is False. If return_line is False, returns the tuple (Pxy, freqs).
Top answer
1 of 2
4

From the documentation for matplotlib.pyplot.hist:

The return value is a tuple (n, bins, patches) or ([n0, n1, ...], bins, [patches0, patches1,...]) if the input contains multiple data.

From the documentation for matplotlib.pyplot.savefig:

Save the current figure.

It looks like you should call savefig in the same way you call hist, not on the result of the hist call.

plt.savefig("{}_temperature.png".format(filename), format='png')
...
2 of 2
2

I've adapted your code and took the liberty to change the several lines creating a figure by list in comprehension of for loops:

import matplotlib.pyplot as plt
# should be equal when using .pylab
import numpy.random as rnd

# generate_data
n_points = 1000
temperature_graph_array = rnd.random(n_points)
feelslike_graph_array = rnd.random(n_points)
windspeed_graph_array = rnd.random(n_points)
windgustspeed_graph_array = rnd.random(n_points)
pressure_graph_array = rnd.random(n_points)
humidity_graph_array = rnd.random(n_points)
list_of_data = [temperature_graph_array,
                feelslike_graph_array,
                windspeed_graph_array,
                windgustspeed_graph_array,
                pressure_graph_array,
                humidity_graph_array]
list_of_names = ['temperature',
                 'feelslike',
                 'windspeed',
                 'windgustspeed',
                 'pressure',
                 'humidity']

# create the figures:
#figure1 = plt.figure()
#figure2 = plt.figure()
#figure3 = plt.figure()
#figure4 = plt.figure()
#figure5 = plt.figure()
#figure6 = plt.figure()
#list_of_figs = [figure1, figure2, figure3, figure4, figure5, figure6]
## could be:
list_of_figs = [plt.figure() for i in range(6)]

# create the axis:
#ax1 = figure1.add_subplot(111)
#ax2 = figure2.add_subplot(111)
#ax3 = figure3.add_subplot(111)
#ax4 = figure4.add_subplot(111)
#ax5 = figure5.add_subplot(111)
#ax6 = figure6.add_subplot(111)
#list_of_axis = [ax1, ax2, ax3, ax4, ax5, ax6]
## could be:
list_of_axis = [fig.add_subplot(111) for fig in list_of_figs]

# plot the histograms
# notice `plt.hist` returns a tuple (n, bins, patches) or
# ([n0, n1, ...], bins, [patches0, patches1,...]) if the input
# contains multiple data
#hist1 = ax1.hist(temperature_graph_array, color="blue")
#hist2 = ax2.hist(feelslike_graph_array, color="blue")
#hist3 = ax3.hist(windspeed_graph_array, color="blue")
#hist4 = ax4.hist(windgustspeed_graph_array, color="blue")
#hist5 = ax5.hist(pressure_graph_array, color="blue")
#hist6 = ax6.hist(humidity_graph_array, color="blue")
#list_of_hists = [hist1, hist2, hist3, hist4, hist5, hist6]
## could be:
list_of_hists = []
for i, ax in enumerate(list_of_axis):
    list_of_hists.append(ax.hist(list_of_data[i], color="blue"))

filename = 'output_graph'
for i, fig in enumerate(list_of_figs):
    name = list_of_names[i].capitalize()
    list_of_axis[i].set_title(name)
    fig.tight_layout()
    fig.savefig("{}_{}.png".format(filename,name), format='png')

Will not post the resulting figures, but this gives me 6 little .png files in the same folder as the script.

Even better, you can use a function to do all that to your data:

def save_hist(data, name, filename):
    fig = plt.figure()
    ax = fig.add_subplot(111)
    ax.hist(data, color="blue")
    ax.set_title(name)
    fig.tight_layout()
    fig.savefig("{}_{}.png".format(filename,name), format='png')
    plt.close(fig)

filename = 'output_graph_2'
for data, name in zip(list_of_data, list_of_names):
    save_hist(data, name, filename)
🌐
Itsourcecode
itsourcecode.com › home › attributeerror
Attributeerror Archives - Itsourcecode.com
March 27, 2023 - This category will discuss the Attributeerror why it occurs and the possible solutions.
🌐
Researchdatapod
researchdatapod.com › home › how to solve python attributeerror: ‘tuple’ object has no attribute ‘append’
How to Solve Python AttributeError: 'tuple' object has no attribute 'append' - The Research Scientist Pod
March 11, 2022 - AttributeError occurs in a Python ... “‘tuple’ object has no attribute ‘append’” tells us that the tuple object does not have the attribute append()....
🌐
Autodesk
download.autodesk.com › global › docs › softimage2014 › en_us › sdkguide › files › script_trouble_ERRORtupleqobjecthasnoattribute.htm
ERROR : 'tuple' object has no attribute
Use the tuple-style syntax as explained in Getting Output Arguments from Methods. ... Except where otherwise noted, this work is licensed under a Creative Commons Attribution-NonCommercial-ShareAlike 3.0 Unported License
🌐
GitHub
github.com › matplotlib › matplotlib › issues › 9973
Slightly misleading errorbar docs that interferes with attempt to animate errorbar · Issue #9973 · matplotlib/matplotlib
December 11, 2017 - In short I would like to animate an errorbar plot, letting it iterate in time over datasets, like in a few canonical plot or histogram examples. My best attempt (below) produces the following error `AttributeError: 'tuple' object has no attribute 'set_animated'.
Author   matplotlib