How to add time x-axis in PlotGraphics?

Please give me some advice when you know it.

I use PlotGraphics to draw 2D line, it is good. But now i hope to draw x-axis with date like [2020-01-01, 2020-01-02, …, 2020-10-01].
then how can i do next?

Thanks much for your advice firstly!

I don’t know if it’s possible to do what you want using PlotGraphics, but it is possible with matplotlib.

See this simple example: (4.6 KB)

I’ve experimented with that lib and hit the same problem! What I’ve done is put some markers at the bottom and clicking them gives the info in the status bar: it first sounds a bit odd but for that one has the whole status bar for display

Thank you Richard for help. I am trying with your method.

Thank you da-dada, very good idea of your advice.

Slightly late, but you might find wxmplot (wxmplot: plotting widgets using wxPython and matplotlib — WXMPLOT: plotting widgets using wxPython and matplotlib) worth looking at, either to use directly or to see possibilities for wrapping of matplotlib with wxPython. An example using timestamps as “x” data is at wxmplot/ at 6e197e0771945854e99cd042e9ec43ef04ce7542 · newville/wxmplot · GitHub

which gives an easy-to-interact with plot panel (and for the example, top-level app). As an example, in the example above, the data spanse something like two weeks worth of events, so the initial display shows only dates. Zooming in (click and drag) enough will show more precision in the time data.

I had a glance at your product and it looks impressive! :blush:
you are talking about ‘reporting mouse positions’ but I couldn’t find anything like self.canvas.GetClosestPoint(self.canvas.GetXY(evt)) of wxPython plot which attempts to return the data at mouse position
have I missed anything or do you find it too vague?

If I understand the question correctly, you are asking about how it reports data values on mouse motion and click events. Wxmplot uses matplotlib’s event mechanism for that (though its wx backend will give some hints about that), mostly because it can conveniently return values in “user/data” coordinates instead of screen / panel coordinates.

For a wxmplot.plotpanel.PlotPanel, has a cursor_callback attribute that you can set after creating the PlotPanel - this should be a callable that will get called with arguments x and y containing the coordinates of every LeftDown event.

If it seems interesting to you, it installs with a simple pip install and the interactive mode and examples should be pretty easy to try out and see if it would work for you.

I think I got you: it’s only for scatterplot and returns x, y of the provided data arrays
the lib.plot method * GetClosestPoint* can be applied to any plot object and returns the object plus the most interesting data of the clicked coordinate: it’s ambitious and, if there are many plot objects close together, can be confusing (* GetClosestPoints* gives all objects in that vicinity and with a little pop-up the user may choose)

@da-dada I believe we are not talking about the same thing. wxmplot.plotpanel.PlotPanel does not have or use a “GetClosestPoint” method. But the positions of mouse motion or LeftDown are recorded in data coordinates, not in Panel or screen coordinates. You can get these values (of the mouse position where the LeftDown event occurred) sent to a callback of your choice for every LeftDown event. If you want to use that to find the closest point in a set of plotted data, you can do that.

I’m not sure what you consider a “scatterplot” to be – we may use this term differently. I consider a scatterplot to be a 2-D plot of data with no importance to the order of the data points, and typically represented as a plot of points. If the order of the data is important, I would call that a Line Plot, and assume that points can be joined with a line or some other join style. wxmplot.plotpanel.PlotPanel supports both.

well, in your docu it says that the callback argument can only be given to a scatterplot (in wxPython it’s simply a PolyMarker object)
are there more quirks?

Ah, the doc there must be wrong. It works for PlotPanel.

are there more quirks?

Yes, certainly.