Reputation: 3001
I want to decrease the markersize for every line I plot with my dataframe. I can set a unique markersize like that:
df = pd.read_csv(file_string, index_col=0)
df.plot(style=['^-','v-','^-','v-','^-','v-'], markersize=8)
I set a different style for every line (I new that there are 6), now I wanted to do the same with the sizes, this doesn't work:
df = pd.read_csv(file_string, index_col=0)
df.plot(style=['^-','v-','^-','v-','^-','v-'], markersize=[16,14,12,10,8,6])
How can I achieve something like this?
Upvotes: 0
Views: 223
Reputation: 206
The above earlier answer works fine for a small number of columns. If you don't want to repeat the same code many times, you can also write a loop that alternates between the markers, and reduces the marker size at each iteration. Here I reduced it by 4 each time, but the starting size and amount you want to reduce each marker size is obviously up to you.
df = pd.DataFrame({'y1':np.random.normal(loc = 5, scale = 10, size = 20),
'y2':np.random.normal(loc = 5, scale = 10, size = 20),
'y3':np.random.normal(loc = 5, scale = 10, size = 20)})
size = 18
for y in df.columns:
col_index = df.columns.get_loc(y)
if col_index % 2 == 0:
plt.plot(df[y], marker = '^', markersize = size)
else:
plt.plot(df[y], marker = 'v', markersize = size)
size -= 4
plt.legend(ncol = col_index+1, loc = 'lower right')
Upvotes: 1
Reputation: 1127
markersize
accepts only a float value not a l ist acording to the documentation.
You can use matplotlib instead, and plot each line independently
import matplotlib.pyplot as plt
import pandas as pd
df = pd.read_csv(file_string, index_col=0)
plt.plot(df[x], df[y1],markersize=16,'^-')
plt.plot(df[x], df[y2],markersize=14,'v-')
#and so on...
plt.show()
Upvotes: 0