要突出显示线图中的上升或下降趋势,可以使用不同的颜色或样式来区分。以下是一些方法:
import matplotlib.pyplot as plt # 生成示例数据 x = range(10) y1 = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10] y2 = [10, 9, 8, 7, 6, 5, 4, 3, 2, 1] plt.plot(x, y1, color='r', label='上升趋势') plt.plot(x, y2, color='g', label='下降趋势') plt.legend() plt.show() import matplotlib.pyplot as plt # 生成示例数据 x = range(10) y1 = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10] y2 = [10, 9, 8, 7, 6, 5, 4, 3, 2, 1] plt.plot(x, y1, linestyle='solid', label='上升趋势') plt.plot(x, y2, linestyle='dashed', label='下降趋势') plt.legend() plt.show() import matplotlib.pyplot as plt # 生成示例数据 x = range(10) y1 = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10] y2 = [10, 9, 8, 7, 6, 5, 4, 3, 2, 1] plt.plot(x, y1, marker='o', label='上升趋势') plt.plot(x, y2, marker='s', label='下降趋势') plt.legend() plt.show() 这些方法可以帮助突出显示线图中的上升或下降趋势,使数据更容易理解和分析。您可以根据具体的数据和需求选择适合的方法来突出显示趋势。