Skip to content
Advertisement

Tag: matplotlib

How to draw a line between a data point and an axis in matplotlib?

Using matplotlib one can use: plt.hlines/vlines to draw segments (e.g. between two data points) plt.axhline/axvline to draw lines relative to the axes My question is: what is the simplest way to do half of each? Typically, drawing a segment from a datapoint to its coordinate on the x or y axis. Answer In my opinion, this is simple enough (4

Matplotlib FuncAnimation Created twice – duplicate when embbeded in tkinter

I have a troubleing bug that i just could not understands it’s origin. Several days of attempts and still no luck. I’m trying to create a line cursor that correspond to played audio with FuncAnimation and for some reason, the animation is created twice ONLY when the callback (line_select_callback) that activates the function is triggered from RectangleSelector widget after drawing

How to create grouped and stacked bars

I have a very huge dataset with a lot of subsidiaries serving three customer groups in various countries, something like this (in reality there are much more subsidiaries and dates): I’d like to make an analysis per subsidiary by producing a stacked bar chart. To do this, I started by defining the x-axis to be the unique months and by

How to label milliseconds axis with datetime labels in matplotlib

I’ve got a sort of timeline plot. I’m drawing rectangles all over it, which is easy to do when time is in milliseconds. But then the x axis labels come out numerical, and I’d rather they be dates. I can convert my timestamps with df[‘timestamp’] = pandas.to_datetime(df[‘timestamp’]) to fix the x axis labels, but then my rectangle drawing math breaks,

Matplotlib: How to plot errorbar plots based on a color map of third category column(Not X and Y)

I’m working on an experimentation personal project. I have the following dataframes: I have used the below code to construct errorbar plot, which works fine: for which the output of confint_plot(treat_repr) looks like this: Now if I run the same plot function on a pre-treatment dataframe confint_plot(pre_treat_repr), the plot looks like this: We can observe from both the plots that

Matplot lib generates Date in X-axis from Jan 1970

I have date index available in the following format: But the following code generates wrong graph: Answer Your dataframe index is likely in the wrong format: str. You can check this with df.info(), if you have something like: If that’s the case, you need to convert index type from str to datetime with: Code example: Without to_datetime conversion: With to_datetime

Advertisement