ax1.plot([0, 1, 2, 3, 4, 5,6], [0, 1, 2, 3, 4, 5,6])设置其颜色
时间: 2023-09-30 08:02:02 浏览: 17
你可以在plot函数中添加color参数来设置线条的颜色,如下所示:
```python
import matplotlib.pyplot as plt
fig, ax1 = plt.subplots()
ax1.plot([0, 1, 2, 3, 4, 5, 6], [0, 1, 2, 3, 4, 5, 6], color='red')
plt.show()
```
这将会把线条的颜色设置为红色。你可以根据需要修改颜色参数的值。除了color参数,还可以使用其他的参数来设置线条的外观和样式。
相关问题
fig, ax1 = plt.subplots() ax1.plot(train_losses, label='Train Loss') ax1.plot(train_accs, label='Train Acc') ax1.set_ylim([0, 1]) ax1.yaxis.set_major_locator(y_major_locator) ax1.set_xlabel('Epoch') ax1.set_ylabel('Loss/Accuracy') ax1.legend() 使两条曲线线条有差别
要使两条曲线线条有差别,可以使用不同的颜色、线型或标记。以下是一些示例代码:
1. 使用不同的颜色:
```
fig, ax1 = plt.subplots()
ax1.plot(train_losses, label='Train Loss', color='red')
ax1.plot(train_accs, label='Train Acc', color='blue')
ax1.set_ylim([0, 1])
ax1.yaxis.set_major_locator(y_major_locator)
ax1.set_xlabel('Epoch')
ax1.set_ylabel('Loss/Accuracy')
ax1.legend()
```
2. 使用不同的线型:
```
fig, ax1 = plt.subplots()
ax1.plot(train_losses, label='Train Loss', linestyle='--')
ax1.plot(train_accs, label='Train Acc', linestyle=':')
ax1.set_ylim([0, 1])
ax1.yaxis.set_major_locator(y_major_locator)
ax1.set_xlabel('Epoch')
ax1.set_ylabel('Loss/Accuracy')
ax1.legend()
```
3. 使用不同的标记:
```
fig, ax1 = plt.subplots()
ax1.plot(train_losses, label='Train Loss', marker='o')
ax1.plot(train_accs, label='Train Acc', marker='s')
ax1.set_ylim([0, 1])
ax1.yaxis.set_major_locator(y_major_locator)
ax1.set_xlabel('Epoch')
ax1.set_ylabel('Loss/Accuracy')
ax1.legend()
```
你可以根据自己的需求选择其中一种或多种方法。
ax1=fig.add_subplot(2,2,1) ax1.plot(bj,'yellowgreen') ax1.plot(cd,'darkorange') ax1.plot(sh,'r') ax1.plot(x,y,'dodgerblue')
这段代码使用了matplotlib库中的子图功能,创建了一个2x2的图表,并在第一个子图中绘制了四条曲线。前三条曲线分别用黄绿色、橙色和红色表示了三个城市在5月每天的降水量,最后一条曲线用天蓝色表示了一个二次函数。具体来说,代码中ax1的含义是获取第一个子图对象,plot函数用来绘制曲线,第一个参数是横坐标数据,第二个参数是纵坐标数据,后面的字符串参数用来设置曲线的颜色。如果你有具体的问题需要解答,请详细描述。
相关推荐
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)