I have the following data:
import pandas as pd
import matplotlib.pyplot as plt
test = pd.DataFrame({"series":["plot1","plot1","plot1","plot2","plot2","plot2"],
"ind_var": [0,1,2,0,1,2],
"dep_var": [0,1,2,0,2,4]})
plot1
is described by f(x)=x
, while plot2
is g(x)=2x
.
I want to plot both series in the same figure and have them share the same x and y axis. I came across this solution, but it requires the data to be in wide format (it needs one line of code per group, which I find inconvenient).
I want to know if there's something similar to the color
argument from ggplot2
. That is, an argument which will plot one column grouped by test["series"]
. The advantage of doing this is more evident when there's multiple series, so you don't have to write one line per series.
I found a similar question and this is as close as I could get:
# test.set_index("ind_var", inplace=True) This is the line I was missing
test.groupby("series")["dep_var"].plot(legend=True)
plt.show()
Is there a way to plot both series in a single figure using something along the lines of grooupby
?