'User defined function two data sets on same plot python

I have written a user-defined function to make a plot. I apply this plot to two different data sets. They appear in two separate figures, but I want them to be plotted on the same figure.

dictionaries = [dic_1,dic_2,dic_3,dic_4,dic_5,dic_6] # array of dictionaries

dataframes={}

#import dataframes
for dict in dictionaries:
        dataframes["field_stars_" + dict["stream"]]=pd.read_csv('/home/'+dict["stream"]+'/'+dict["lens"]+'.csv')

def RMS_SNRvGMAG(dataframes,dict):
        plt.scatter(dataframes["field_stars_" + dict["stream"])
      
RMS_SNRvGMAG(dataframes,dic_1)
RMS_SNRvGMAG(dataframes,dic_6)

Where dict contains dictionaries of naming conventions for the data sets. The said data sets are stored in dataframes. When I run the code: two figures are generated. How do I get these two graphs to be on the same plot?



Solution 1:[1]

The following is a start, though sharing a minimal working example (i.e. actual code and data) will make it possible to provide a better answer.

toy data, and imports:

import matplotlib.pyplot as plt
import numpy as np

t = np.arange(0.0, 2.0, 0.01)
s = 1 + np.sin(2 * np.pi * t)
s2 = 2 + np.sin(2 * np.pi * t)

One approach to plotting:

fig, ax = plt.subplots()
ax.plot(t, s)  # <-- data for the first curve
ax.plot(t, s2) # <-- data for the second curve, note that they share 't'

ax.set(xlabel='time (s)', ylabel='Y',
       title='Two lines')

plt.show()

An alternative:

plt.scatter(t,s)  # <-- you could call 'RMS_SNRvGMAG' here
plt.scatter(t,s2) 
plt.show() 

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1