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')
...
Answer from TigerhawkT3 on Stack Overflow
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)
🌐
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() ...
Discussions

numpy - Python error code AttributeError: 'tuple' object has no attribute 'save' - Stack Overflow
I made a Python steganography program. And then I want to save the outputted image with syntax object.save(). In the console log shows an error, that said AttributeError: 'tuple' object has no More on stackoverflow.com
🌐 stackoverflow.com
November 30, 2019
Rendering Matplotlib AxesSubplots in Streamlit
Hi everyone, I’m building a streamlit app, and am trying to make use of Seaborn plots in the application. One of my issues is that when I try and render a scatter plot using st.pyplot I get the following error message: AttributeError: 'AxesSubplot' object has no attribute 'savefig' Importantly, ... More on discuss.streamlit.io
🌐 discuss.streamlit.io
1
1
September 19, 2020
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
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) More on github.com
🌐 github.com
2
July 8, 2015
🌐
Stack Overflow
stackoverflow.com › users › 7563872 › ryan-witek
User Ryan Witek - Stack Overflow
Why am I getting "AttributeError: 'tuple' object has no attribute 'savefig'"? Mar 14, 2017 · 0 · How do I write a Python function capable of reading and overwriting a text file? Feb 14, 2017 · -1 · Why am I receiving a "ValueError" message for this program?
🌐
LearnDataSci
learndatasci.com › solutions › python-attributeerror-tuple-object-has-no-attribute
Python AttributeError: 'tuple' object has no attribute – LearnDataSci
The error AttributeError: 'tuple' object has no attribute is caused when treating the values within a tuple as named attributes.
🌐
Stack Overflow
stackoverflow.com › questions › 59117289 › python-error-code-attributeerror-tuple-object-has-no-attribute-save
numpy - Python error code AttributeError: 'tuple' object has no attribute 'save' - Stack Overflow
November 30, 2019 - Why am I getting "AttributeError: 'tuple' object has no attribute 'savefig'"? 2 · TypeError at images/create - __init__() got an unexpected keyword argument 'save' 3 · How to save solve this: saving images with PIL.Image · 4 · Resizing images gives tuple error ·
🌐
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   vollmersj
Find elsewhere
🌐
GitHub
github.com › infiniflow › ragflow › issues › 7466
[Bug]: Crash when proceeding with figure enhancement: 'tuple' object has no attribute 'save' · Issue #7466 · infiniflow/ragflow
May 5, 2025 - 14:43:12 Page(1~3): [ERROR]'tuple' object has no attribute 'save' 14:43:12 Page(1~3): [ERROR]Internal server error while chunking: not enough values to unpack (expected 2, got 1) 14:43:12 [ERROR][Exception]: not enough values to unpack (expected 2, got 1) Should not crash ·
Author   raffaem
🌐
CopyProgramming
copyprogramming.com › howto › python-attributeerror-tuple-object-has-no-attribute-print
Python: Tuple object lacks 'print' attribute
June 4, 2023 - The output can either be a tuple with three MSDT codes ( n , bins , and patches ), or a list with multiple MSDT codes ( n0 , n1 , etc.) along with two additional MSDT codes ( bins and patches0 , patches1 , etc.) if the input has multiple data. According to the information provided in the documentation related to matplotlib.pyplot.savefig . Save the current figure. It seems that to make the call correctly, savefig should be called in a similar manner as hist . It is not advisable to call it based on the outcome of the hist call.
🌐
GitHub
github.com › matplotlib › matplotlib › issues › 16811
Specifying a Marker as a Tuple seems broken in 3.2 · Issue #16811 · matplotlib/matplotlib
March 17, 2020 - AttributeError: 'IdentityTransform' object has no attribute 'scale' In version 3.1.2, this error does not occur. It looks like ... def main(): import matplotlib.pyplot as plt fig = plt.figure() fig.add_axes() ax = fig.gca() ax.plot([0, 1, 2], [0, 1, 2], marker=(3, 2, 0.0)) fig.savefig('foo.png') if __name__ == '__main__': main()
Author   Erotemic
🌐
You.com
you.com › chat › 'tuple' object has no attribute 'savefig'
'tuple' object has no attribute 'savefig' 🔎 Your Personalized AI Assistant.
Conversational and continuously learning, You.com enhances web search, writing, coding, digital art creation, and solving complex problems.
🌐
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.
🌐
freeCodeCamp
forum.freecodecamp.org › python
Attribute error: AxesSubplot' object has no attribute 'savefig' - Python - The freeCodeCamp Forum
May 14, 2021 - Tell us what’s happening: I got an error message on the Time series challenge. Could anyone kindly advise? Thanks Traceback (most recent call last): File "main.py", line 7, in time_series_visualizer.draw_bar_plot() File "/home/runner/boilerplate-page-view-time-series-visualizer-1/time_series_visualizer.py", line 43, in draw_bar_plot fig.savefig('bar_plot.png') AttributeError: 'AxesSubplot' object has no attribute 'savefig' exit status 1 My code is as below Your code so ...
🌐
GitHub
github.com › ragulin › face-recognition-server › issues › 9
AttributeError: 'tuple' object has no attribute 'save' · Issue #9 · ragulin/face-recognition-server
July 21, 2016 - In the function called load_images_to_db(path): I receive an error message as follow above: in load_images_to_db label.save() AttributeError: 'tuple' object has no attribute 'save' ...
Author   lcsbonilla
🌐
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 ...
🌐
PyTorch Forums
discuss.pytorch.org › vision
'tuple' object has no attribute 'to' in pytorch - vision - PyTorch Forums
June 19, 2021 - I got this error while trying to test CNN model. I already checked type about this error point’variable. Here is error point 10. imgs = imgs.to(device) #imgs type <class ‘torch.Tensor’> —> 11 …