plot - 如何将背景图像放在 Rust 绘图仪库中的绘图中
问题描述
我正在尝试在飞机上绘制汽车旅行。我正在使用绘图仪库。下面是trips绘制过程的一些代码示例:
pub fn save_trips_as_a_pic<'a>(trips: &CarTrips, resolution: (u32, u32))
{
// Some initializing stuff
/// <...>
let root_area =
BitMapBackend::new("result.png", (resolution.0, resolution.1)).into_drawing_area();
root_area.fill(&WHITE).unwrap();
let root_area =
root_area.margin(10,10,10,10).titled("TITLE",
("sans-serif", 20).into_font()).unwrap();
let drawing_areas =
root_area.split_evenly((cells.1 as usize, cells.0 as usize));
for (index, trip) in trips.get_trips().iter().enumerate(){
let mut chart =
ChartBuilder::on(drawing_areas.get(index).unwrap())
.margin(5)
.set_all_label_area_size(50)
.build_ranged(50.0f32..54.0f32, 50.0f32..54.0f32).unwrap();
chart.configure_mesh().x_labels(20).y_labels(10)
.disable_mesh()
.x_label_formatter(&|v| format!("{:.1}", v))
.y_label_formatter(&|v| format!("{:.1}", v))
.draw().unwrap();
let coors = trip.get_points();
{
let draw_result =
chart.draw_series(series_from_coors(&coors, &BLACK)).unwrap();
draw_result.label(format!("TRIP {}",index + 1)).legend(
move |(x, y)|
PathElement::new(vec![(x, y), (x + 20, y)], &random_color));
}
{
// Here I put red dots to see exact nodes
chart.draw_series(points_series_from_trip(&coors, &RED));
}
chart.configure_series_labels().border_style(&BLACK).draw().unwrap();
}
}
我现在在 Rust Plotters 上得到了什么:
因此,在“result.png”图像文件中绘制后,我很难理解这些“线条”,因为我看不到地图本身。我想,这个库中有一些方法可以将地图“map.png”放在情节的背景中。如果我使用 Python,这个问题将这样解决:
# here we got a map image;
img: Image.Image = Image.open("map-image.jpg")
img.putalpha(64)
imgplot = plt.imshow(img)
# let's pretend that we got our map size in pixels and coordinates
# just in right relation to each other.
scale = 1000
x_shift = 48.0
y_shift = 50.0
coor_a = Coordinate(49.1, 50.4)
coor_b = Coordinate(48.9, 51.0)
x_axis = [coor_a.x, coor_b.x]
x_axis = [(element-x_shift) * scale for element in x_axis]
y_axis = [coor_a.y, coor_b.y]
y_axis = [(element-y_shift) * scale for element in y_axis]
plt.plot(x_axis, y_axis, marker='o')
plt.show()
好吧,这在 Python 上很容易,但我不知道如何在 Rust 上做类似的事情。
解决方案
推荐阅读
- javascript - 在一页上添加多个图片库
- pyspark - 如何可视化 pyspark ml 的 LDA 或其他聚类
- powerbi - 如何根据分类值有条件地格式化颜色?
- firebase - 如何在 Firebase 仪表板中手动输入数据
- google-apps-script - 如何使用 Apps 脚本将 Google 表格内容粘贴到 Google 幻灯片中?
- amazon-web-services - 无法在我的浏览器中使用弹性 IP 访问 AWS 实例
- python - AttributeError:模块“tensorflow.python.training.checkpointable”没有属性“CheckpointableBase”
- java - java:扫描器在使用 useDelimiter 时要求一个额外的值
- html - 如何删除日期选择器上突出显示的日期
- c# - 方法语法中的 LINQ 查询是否需要 Select() 方法?