3

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.

image here

3
  • What does your data look like? time steps as index and cells as columns? Commented Nov 25, 2019 at 18:00
  • Exactly. I currently have a pandas dataframe with time steps as index and each cell as a column. Commented Nov 25, 2019 at 18:02
  • 1
    I 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. Commented Nov 25, 2019 at 18:05

2 Answers 2

1

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.htmlenter image description here

I wish I had these tools when I worked in a lab. Would have been so much nicer than what I did back then.

Sign up to request clarification or add additional context in comments.

Comments

0

You can do, for example:

your_df.plot(subplots=True, layout=(10,30));

Comments

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.