选项按钮制图_如何创建一个按钮来交换绘图中的数据

选项按钮制图

I recently wanted to create a button for a plotly (the Python library) plot that exchanges the underlying data. I got stuck in the middle and since I couldn’t find much on Google, I thought it might be worth sharing this quick one with you.

我最近想为绘图(Python库)绘图创建一个按钮,以交换基础数据。 我被困在中间,由于我在Google上找不到很多东西,所以我认为值得与您快速分享这个内容。

A plotly plot can be updated by using passing updatemenus to the fig.update_layout() method. In the plotly reference, we find that there are two ways (more precisely types) to update the data, dropdown and buttons. In this post, we go for buttons.

可以通过将updatemenus传递给fig.update_layout()方法来更新绘图。 在可参考的参考资料中 ,我们发现有两种方法(更确切地说是类型)来更新数据: 下拉菜单按钮 。 在这篇文章中,我们去寻找按钮。

There are four methods to change something in the plot by pressing the button: restyle, relayout, animate, and update. They determine which plotly.js function is called to modify the chart, in other words: what you can change in the plot. We want to modify the data but we might also need to adapt the corresponding axis labels, therefore, it is always sensible to go for update, which allows us to do both. Let’s create a data frame and a quick scatter plot to see how this works in action! Imagine you want to plot the relationship between temperature in degree Celsius and how many ice cream cones or drinks are sold per hour. After all, both should

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
要在 MFC 创建一个带有倒角的按钮,你可以使用自定义绘制来实现。下面是一个示例,示如何创建一个带有倒角的按钮: 1. 在 MFC 对话框的资源编辑器,将按钮控件的类型设置为 "Owner Drawn"。 2. 打开对话框的类文件(通常是 `.cpp` 文件)。 3. 在对话框类的 `OnInitDialog()` 函数添加以下代码: ```cpp BOOL YourDialogClass::OnInitDialog() { CDialogEx::OnInitDialog(); // 获取按钮控件对象 CButton* pButton = (CButton*)GetDlgItem(IDC_BUTTON1); // 设置按钮为自绘制样式 pButton->ModifyStyle(0, BS_OWNERDRAW); return TRUE; } ``` 4. 在对话框类添加 `OnDrawItem()` 函数,并使用 `ODA_DRAWENTIRE` 和 `ODS_BUTTON` 标志处理自定义绘制: ```cpp void YourDialogClass::OnDrawItem(int nIDCtl, LPDRAWITEMSTRUCT lpDrawItemStruct) { // 检查控件ID是否为按钮的ID if (nIDCtl == IDC_BUTTON1) { // 获取按钮绘图设备上下文和矩形区域 CDC* pDC = CDC::FromHandle(lpDrawItemStruct->hDC); CRect rect = lpDrawItemStruct->rcItem; // 绘制按钮背景 if (lpDrawItemStruct->itemState & ODS_SELECTED) pDC->FillSolidRect(rect, RGB(192, 192, 192)); // 按下时的颜色 else pDC->FillSolidRect(rect, RGB(255, 255, 255)); // 正常状态的颜色 // 绘制按钮边框和倒角 CPen pen(PS_SOLID, 1, RGB(0, 0, 0)); // 边框颜色 CPen* pOldPen = pDC->SelectObject(&pen); pDC->RoundRect(rect, CPoint(10, 10)); // 倒角大小 pDC->SelectObject(pOldPen); // 获取按钮文本 CString buttonText; GetDlgItemText(IDC_BUTTON1, buttonText); // 绘制按钮文本 pDC->SetBkMode(TRANSPARENT); pDC->DrawText(buttonText, rect, DT_CENTER | DT_VCENTER | DT_SINGLELINE); } else { CDialogEx::OnDrawItem(nIDCtl, lpDrawItemStruct); } } ``` 在上述代码,我们使用 `FillSolidRect()` 函数绘制按钮的背景,根据按钮的状态选择不同的颜色。然后,我们使用 `RoundRect()` 函数绘制带有倒角的按钮边框。最后,使用 `DrawText()` 函数绘制按钮文本。 通过以上步骤,你可以创建一个带有倒角的自绘制按钮。你可以根据需要自行调整颜色和倒角大小。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值