在 matplotlib 或 bokeh 中连续改变极坐标图中线条的颜色

问题描述 投票:0回答:0

我想在极坐标图中绘制几年的日平均温度。我到了那里,但到目前为止,经过一年多的数据,线条颜色保持不变,尚不清楚哪个部分属于哪一年。因此,我想不断改变线条的颜色。我找不到这个选项。

这里是极坐标图的代码。 谢谢你的帮助

import pandas as pd
import numpy as np
import matplotlib.pyplot as plt
import matplotlib.dates as mdates


# Create polar plot
fig, ax = plt.subplots(subplot_kw={'projection': 'polar'})

# Set tick positions and labels for the angle axis
months = mdates.MonthLocator()  # every month
months_fmt = mdates.DateFormatter('%b')  # month abbreviation
ax.xaxis.set_major_locator(months)
ax.xaxis.set_major_formatter(months_fmt)

# Convert dates to angles in radians
#angles = np.deg2rad((weather21_day.index).days * 360 / 365)
# Subtract January 1st from each datetime
delta = (temp_av_day.index - pd.Timestamp('2021-01-01 00:00:00+00:00') )/ np.timedelta64(1, 'D')
days_diff = np.asarray(delta)
angles = np.deg2rad(days_diff * 360 / 365)



#Plot temperature as radius
ax.plot(angles, temp_av_day['T out']+20)
#ax.plot(angles, weather22_day['T out']+20)


# Show the plot
plt.show()
python-3.x matplotlib polar-coordinates
© www.soinside.com 2019 - 2024. All rights reserved.