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
Tag: matplotlib
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 put text at a fixed position when updating an animation
Here’s the whole code: (main problem is explained below) I used matplotlib.animation to animate the graph. Everything went good. Now I wanted to put the seed (the number) in top right corner of the graph, so I did this: plt.text((i+5)*0.8,o*0.88, (“Seed: ” +str(N))) This add the text at every frame iteration (as I wanted) but the previous text remains in
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 do I display the top & bottom 5 row values along with custom row values in Matplotlib?
I have a dataframe that’s about 750 odd rows, which is obviously excessive for a traditional bar chart. What I would like to do is have it display the Top 5 entries, the specific criteria that I’m looking for, and the bottom 5 entries. The dataframe is something like this: What I want to be able to do is display
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
How to get rid of scientific notation on bar labels in matplotlib?
How could I format the bar labels to remove the scientific notation? Answer As already suggested by BigBen in the comment, you can pass fmt parameter to matplotlib.axes.Axes.bar_label; you can use %d for integers:
Matplotlib: highlight range at the bottom of plot
I need to produce a plot with certain ranges highlighted. The problem is that I cannot use axvspan that would fill the span area from top to bottom. I need to limit the spanned area only to the bottom, as can be seen in the image below, where the range 0.5-1.5 is highlighted: Is there a way to achieve this