c++ - vtk 图表 - 如何在轴线末端绘制轴标签?

标签 c++ vtk qvtkwidget

是否可以在标签的末尾绘制轴标签? 详情见图片:

http://habrastorage.org/files/94f/41a/b18/94f41ab1897a4bde815644bf287b4af9.png

如果可能,怎么做?

vtkNew<vtkContextView> contextView;

vtkNew<vtkTable> table;
vtkNew<vtkChartXY> chart;
vtkNew<vtkDoubleArray> timeAxis;
vtkNew<vtkDoubleArray> realDataAxis;
vtkNew<vtkDoubleArray> measuredDataAxis;

// ...

contextView->SetInteractor(vtkWidget->GetInteractor());
vtkWidget->SetRenderWindow(contextView->GetRenderWindow());

timeAxis->SetName("t");
realDataAxis->SetName("x(t)");
measuredDataAxis->SetName("x*(t)");

table->AddColumn(timeAxis.Get());
table->AddColumn(realDataAxis.Get());
table->AddColumn(measuredDataAxis.Get());

chart->SetShowLegend(true);
auto legend = chart->GetLegend();
legend->GetLabelProperties()->SetFontSize(14);
legend->GetLabelProperties()->SetFontFamilyToTimes();

auto xAxis = chart->GetAxis(vtkAxis::BOTTOM);
xAxis->SetTitle(QApplication::translate("DataSetChartWidget", "t").toStdString());

auto xTitleProps = xAxis->GetTitleProperties();
xTitleProps->SetFontSize(14);
xTitleProps->SetFontFamilyToTimes();

auto xLabelProps = xAxis->GetLabelProperties();
xLabelProps->SetFontSize(14);
xLabelProps->SetFontFamilyToTimes();

auto yAxis = chart->GetAxis(vtkAxis::LEFT);
yAxis->SetTitle(QApplication::translate("DataSetChartWidget", "x(t), x*(t)").toStdString());

auto yTitleProps = yAxis->GetTitleProperties();
yTitleProps->SetFontSize(14);
yTitleProps->SetFontFamilyToTimes();

auto yLabelProps = yAxis->GetLabelProperties();
yLabelProps->SetFontSize(14);
yLabelProps->SetFontFamilyToTimes();

contextView->GetScene()->AddItem(chart.Get());

绘图代码:

auto realPlot = chart->AddPlot(vtkChart::LINE);
realPlot->SetInputData(table.Get(), 0, 1);

auto measuredPlot = chart->AddPlot(vtkChart::POINTS);
measuredPlot->SetInputData(table.Get(), 0, 2);

最佳答案

您可以设置坐标轴标题的垂直和水平对齐方式。

例如

myVtkChart->GetAxis(0)->GetTitleProperties()->SetJustificationToLeft();

在你的情况下调用就足够了

xTitleProps->SetJustificationToRight();
yTitleProps->SetJustificationToLeft();

但标题宽度似乎没有缩放到轴长度。 这意味着可能需要在您的标题字符串中放入一些空格以获得预期的结果。

关于c++ - vtk 图表 - 如何在轴线末端绘制轴标签?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27462126/

相关文章:

c++ - 如何将 char 数组作为对函数和 memcpy 的引用传递

c++ - 在 C++ 中以特定格式打印 openCV Mat 内容

linux - VTK 应用程序的可移植性

C++11 没有匹配函数来调用‘std::vector

c++ - 无法将字符串参数传递给派生类成员函数 C++

python - VTK 渲染窗口图像到 numpy 数组

c++11 - vtkImageResliceMapper 中的 VTK 相机更新问题

c++ - CMake 错误 - cmTryCompileExec 已停止工作 (VTK)

c++ - 具有 >50 个(移动) Actor 的 Vtk Qt 场景

c++ - 隐藏 vtkOutputWindow