我有一个关于如何正确地将散点图和线放入一个图表的问题。
以下是代码:
id = 'card0';
var div = Div(id); //will have things about comparisons and stuff
var card = Card(id);
card.setName();
card.setImage();
可以看出散点图反映不正确(显示为线条)
谢谢!
答案 0 :(得分:0)
将data.Weight
分散到data.Height
:
ax.plot(data.Weight, data.Height , 'o', markerfacecolor = 'red')
答案 1 :(得分:0)
这些 CSV 文件是从 kaggle 天气数据下载的,它显示了如何绘制散点图和添加了 fill_between 的线图:图像已附加
import csv
import matplotlib.pyplot as plt
from datetime import datetime
with open('antigua.csv') as antigua_data :
reader = csv.reader(antigua_data)
column_head= next(reader)
for index,column in enumerate(column_head) :
print(index,column)
antigua_temperature = []
for antigua_temp in reader :
daily_temp = float(antigua_temp[10])
antigua_temperature.append(daily_temp)
with open('antigua.csv') as antigua_data:
reader = csv.reader(antigua_data)
column_head = next(reader)
dates = []
for days in reader :
date = datetime.strptime(days[3],'%Y-%m-%d')
dates.append(date)
with open('train.csv') as antigua_data :
reader = csv.reader(antigua_data)
column_head= next(reader)
afghan_temperature =[]
for afghan_temp in reader :
day_temp = float(afghan_temp[10])
afghan_temperature.append(day_temp)
fig, ax = plt.subplots()
ax.plot(dates,antigua_temperature,c='red',alpha=0.5)
ax.scatter(dates,antigua_temperature)
ax.scatter(dates,afghan_temperature)
ax.plot(dates,afghan_temperature,c='blue',alpha=0.5)
plt.fill_between(dates, antigua_temperature, afghan_temperature, facecolor='red', alpha=0.1)
fig.autofmt_xdate()
ax.set_xlabel('Dates')
ax.set_ylabel('Temperature')
ax.set_title(f'A Comparison of Afghanistan weather and antigua')
plt.show()
答案 2 :(得分:-1)
假设您希望变量data
显示在散点图中,
ax.scatter(data.Weight, data.Height , color = 'red')