I have fluorescence values over a period of 200 time steps for 300 individual cells. I want to plot them all on the same figure stacked one on top of another. I don't want to plot a stacked area plot. The image below is what I'm looking for, but essentially it's each cell's data plotted on its own individual y-axis, with all cells having the same x-axis.
-
What does your data look like? time steps as index and cells as columns?Quang Hoang– Quang Hoang2019-11-25 18:00:19 +00:00Commented Nov 25, 2019 at 18:00
-
Exactly. I currently have a pandas dataframe with time steps as index and each cell as a column.Munib Hasnain– Munib Hasnain2019-11-25 18:02:38 +00:00Commented Nov 25, 2019 at 18:02
-
1I would either create subplots that share an x axis or I would add an offset value to the y values of each dataset to force the separation.mauve– mauve2019-11-25 18:05:10 +00:00Commented Nov 25, 2019 at 18:05
2 Answers
The main plotting tools (that work with pandas) in python are matplotlib (older) and seaborn (newer and a littler fancier).
Looking at seaborn's docs (https://seaborn.pydata.org/tutorial/axis_grids.html) and a recipe page (https://python-graph-gallery.com/122-multiple-lines-chart/) for multi-component composite plots, you can show your fluorescence data like this:
# libraries
import matplotlib.pyplot as plt
import numpy as np
import pandas as pd
# Data
df=pd.DataFrame({'x': range(100),
'trace1': np.random.randn(100),
'trace2': np.random.randn(100)+10,
'trace3': np.random.randn(100)+20})
# multiple line plot
plt.plot( 'x', 'trace1', data=df, marker='', color='black', linewidth=2)
plt.plot( 'x', 'trace2', data=df, marker='', color='black', linewidth=2)
plt.plot( 'x', 'trace3', data=df, marker='', color='black', linewidth=2, label="GluK1c")
plt.legend()
I'm not in love with that hack (adding numbers to each trace y-value) since there ought to be a way to offset your y-axis values within matplotlib but I couldn't find that option when googling.
In this case, because you want minimalist black line traces (what neuroscience journals expect), matplotlib and seaborn are comparable.
For a plethora of legend position/formatting options, see https://matplotlib.org/3.1.1/api/_as_gen/matplotlib.pyplot.legend.html
I wish I had these tools when I worked in a lab. Would have been so much nicer than what I did back then.
