Here is my code:
import matplotlib.pyplot as plt
t = np.array([[0,1,2,3,4,5,6,7,8,9,10,11,12]])
g1 = np.array([[2,2.2,3,4,3.5,4.3,4.9,6,7.9,9.9,9.5,9.6,10]])
plt.figure(1)
plt.plot(t,g1)
Nothing happens. plt.show() does not help. I know it's because I use double brackets in t and g1 but I need that for my script. How do keep my double brackets, i.e. dimensions, AND being able to plot?
EDIT: OK, I had to transpose them in order to plot them - is there no way that Python automatically detects that?? (I am used to Matlab where the dimensions in this regard doesn't matter for plotting)
1 Answer 1
You can squeeze the dimensions of t and g1 when you plot them:
plt.plot(t.squeeze(), g1.squeeze())
Squeezing removes all singleton dimensions, thus the plot is with 1-dimensional arrays.
You noticed that if you transpose it, the plot works. That's because matplotlib plots columns when you feed it 2d data. Plot makes lines and there are no lines to make when all the columns only have one value. Another way to see this is to make a scatter plot.
plt.plot(t, g1, 'o')