1

I have multiple datasets that I need to be plotted on the same axes. Just an example of the datasets are: Dataset 01 as two separate lists:

Waves          Values
340            520
341            532
342            536
.              .
.              .
2500           720

Dataset 02 as a dataframe df:

Wavelength      Data
320             560
350             572
.               .
.               .
2650            780

My attempt at the plot is as follows:

fig,ax=plt.subplots(figsize=(15, 10))
ax = plt.plot(x = Waves , y = Values)   # list names
df.plot(ax=ax, x='Wavelength', y='Data')
plt.show()

I get the following error:

AttributeError: 'list' object has no attribute 'get_figure'

SAMPLE OUTPUT GRAPH

0

1 Answer 1

3

You redefine the axes ax, created in the first line, to be a list of lines via ax=plt.plot(..). Remove this redefinition.

fig,ax=plt.subplots(figsize=(15, 10))
ax.plot(Waves, Values)
df.plot(ax=ax, x='Wavelength', y='Data')
plt.show()
Sign up to request clarification or add additional context in comments.

2 Comments

this did get rid of the error, but it doesn't plot the (x= Waves, y = Values) at all....just the df.plot (only the blue line plot in my sample output pic)
Sorry, I just copied that from your code without testing as there is no minimal reproducible example. The problem is that matplotlib plot's x and y argument are no named arguments.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.