[英]Setting plot linestyles afterwards
我正在循環繪制圖:
cities = grouped_price.index.levels[0] # list of cities
dates = grouped_price.index.levels[1] # list of dates, which
# are 1st day of each month
linestyles = ['-', '-.', '--', '-.-', ':']
for city in cities[0:1]:
for month in dates: # loop over dates, which are grouped by month
legend = legend + [month.strftime("%B")] # month in text
ax = grouped_price.loc[city, month]['Amount'].plot()
plt.show()
之后如何設置線型 ? 如果我寫
ax = grouped_price.loc[city, week]['Amount'].plot(style = linestyles)
環內,它只是使用了所有行的第一線型 。
顏色和線條粗細同樣的問題。 我找到了一種設置厚度(在每條線上循環)的迭代解決方案,但是有沒有更簡單的方法? 謝謝。
如果您擁有相同數量的月份和線型,則可以執行以下操作:
linestyles = ['-', '-.', '--', '-.-', ':']
for city in cities[0:1]:
for month,ls in zip(dates, linestyles): # loop over dates, which are grouped by month and linestyles
legend = legend + [month.strftime("%B")] # month in text
ax = grouped_price.loc[city, month]['Amount'].plot(style = ls)
plt.show()
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.