matplotlib plot circle marker
To plot a circle marker using the Matplotlib library in C, you can follow these steps:
- Include the necessary headers:
#include <cairo.h>
#include <gtk/gtk.h>
- Define the callback function to draw the circle:
gboolean on_draw_event(GtkWidget widget, cairo_t cr, gpointer user_data) {
// Get the width and height of the widget
int width, height;
gtk_widget_get_size_request(widget, &width, &height);
// Set the circle's radius
int radius = 50;
// Set the circle's position
int x = width / 2 - radius;
int y = height / 2 - radius;
// Set the circle's color
double red = 1.0;
double green = 0.0;
double blue = 0.0;
// Draw the circle
cairo_set_source_rgb(cr, red, green, blue);
cairo_arc(cr, x + radius, y + radius, radius, 0, 2 * M_PI);
cairo_fill(cr);
return FALSE;
}
- Create the main window and connect the callback function to the
draw
event:
int main(int argc, char *argv[]) {
// Initialize GTK
gtk_init(&argc, &argv);
// Create the main window
GtkWidget *window = gtk_window_new(GTK_WINDOW_TOPLEVEL);
// Set the window size
gtk_widget_set_size_request(window, 400, 400);
// Connect the callback function to the draw event
g_signal_connect(window, "draw", G_CALLBACK(on_draw_event), NULL);
// Show the main window
gtk_widget_show_all(window);
// Run the GTK main loop
gtk_main();
return 0;
}
- Compile and run the code. You will see a window with a red circle marker in the center.
Note: This code uses the GTK library to create the window and handle events. You need to have the GTK development libraries installed on your system to compile and run this code.