matplotlib

x-Axis ticks as dates

左心房为你撑大大i 提交于 2021-01-28 14:33:39
问题 I have some data I would like to plot consisting of two columns, one being an amount count and the other column being the actually date recorded. When plotting this, since I have over 2000 dates, it makes more sense to not show every single date as a tick on the x -axis, otherwise it won't be readable. However, I am having a hard time making the dates show up on the x -axis with some kind of logic. I have tried using the in-built tick locators for matplotlib but it's not working somehow. Here

Histogram color by class

我的梦境 提交于 2021-01-28 13:55:03
问题 I have a pandas dataframe with 2 columns "height" and "class, class is a column with 3 values 1,2 and 5. Now i want to make a histogram of the height data and color by class. plot19_s["vegetation height"].plot.hist(bins = 10) this is my histogram but now I want to see the different classes by a change in color in the histogram. 回答1: Since I'm not sure if the potential duplicate actually answers the question here, this is a way to produce a stacked histogram using numpy.histogram and

Plot a list of tuples on x axis

 ̄綄美尐妖づ 提交于 2021-01-28 12:45:18
问题 I've data like the following x = [(1,0), (0, 1), (2, 1), (3, 1)] y = [1, 4, 8.5, 17.5] and I would like to plot in the following way But matplotlib considers x as a 2 column vector so the y data is plotted twice. Suggestions on how to generate a plot in the above-mentioned format will be really helpful. 回答1: You can also convert the tuples to strings and plot a categorical scatter: plt.scatter([str(i) for i in x], y) 回答2: You can use set_xticks and set_xticklabels methods of an Axes object x

Keep the same color order for lines between different plots? I dropped one line, colors are now rearranged

我只是一个虾纸丫 提交于 2021-01-28 12:42:57
问题 I have a pandas dataframe, and would like to compare two line plots or "spaghetti" plots. The 2nd plot has one column removed from the dataframe. However it gets a bit confusing when the colors rearrange between plots. An example, weekly sales of eight shops: (df.plot(figsize=(20,10),lw=2.5,linestyle='--') .legend(loc=2, prop={'size': 13})) I can see shop1 (blue) is drowning out the others. So I decide to remove shop1, and plot it again: # drop shop 1 df.drop('shop1',axis=1,inplace=True) #

Pyplot: Display label values when mouse hover point

纵饮孤独 提交于 2021-01-28 12:42:38
问题 I have a very basic plot, for which I would like to add the ability to display values when mouse hovers over data points on the plot. The code I use to create my line graph is as follows: df_all['count'] = pd.to_numeric(df_all['count']) cumulative = df_all['count'].cumsum() cumulative.plot() plt.plot() print(plt.show()) Many thanks in advance 回答1: Further to the comment regarding Plotly, here is a very simple example of how to plot a graph, with hoverable trends. Example code: import random

Plot a list of tuples on x axis

佐手、 提交于 2021-01-28 12:41:08
问题 I've data like the following x = [(1,0), (0, 1), (2, 1), (3, 1)] y = [1, 4, 8.5, 17.5] and I would like to plot in the following way But matplotlib considers x as a 2 column vector so the y data is plotted twice. Suggestions on how to generate a plot in the above-mentioned format will be really helpful. 回答1: You can also convert the tuples to strings and plot a categorical scatter: plt.scatter([str(i) for i in x], y) 回答2: You can use set_xticks and set_xticklabels methods of an Axes object x

Reading higher frequency data in thread and plotting graph in real-time with Tkinter

◇◆丶佛笑我妖孽 提交于 2021-01-28 12:25:19
问题 In the last couple of weeks, I've been trying to make an application that can read EEG data from OpenBCI Cyton (@250Hz) and plot a graph in 'real-time'. What seems to work better here are threads. I applied the tips I found here 1 to communicate the thread with Tkinter, but the application still doesn't work (gives me the error RecursionError: maximum recursion depth exceeded while calling a Python object ). Maybe I'm doing something wrong because I'm trying to use multiple .py files? See

Reading higher frequency data in thread and plotting graph in real-time with Tkinter

最后都变了- 提交于 2021-01-28 12:17:24
问题 In the last couple of weeks, I've been trying to make an application that can read EEG data from OpenBCI Cyton (@250Hz) and plot a graph in 'real-time'. What seems to work better here are threads. I applied the tips I found here 1 to communicate the thread with Tkinter, but the application still doesn't work (gives me the error RecursionError: maximum recursion depth exceeded while calling a Python object ). Maybe I'm doing something wrong because I'm trying to use multiple .py files? See

Python:Plot scipy plot on top of voronoi diagram

偶尔善良 提交于 2021-01-28 11:58:52
问题 I am trying to plot on top of scipy plot. Used [this solution] (Python: plot on top of scipy plot? (voronoi)) but still cannot get single plot. Can anyone help? Thanks in advance... Sample plots are the following and trying to overlap them: Voronoi Diagram and Scatter Plot vor = Voronoi( points ) voronoi_plot_2d(vor) import matplotlib.pyplot as plt import csv x = [] y = [] with open('Junctions.csv','r') as csvfile: plots = csv.reader(csvfile, delimiter=',') for row in plots: x.append((row[0])

How to edit the fig with the new mplfinance package?

╄→гoц情女王★ 提交于 2021-01-28 11:58:50
问题 I can't seem to add any text, rotate axis, change the background color, etc with the new mplfinance. With the old mpl-finance, I just do fig, ax = plt.subplots() and edit the fig and ax however I want to like: fig.text(0.96, 1, 'some text', size=9, fontweight='bold',color='black', ha="right") or plt.legend( loc='upper left') Does anyone know how to do that with the new package? 回答1: To gain access to mplfinance's Figure and Axes objects, there are two ways: Method 1. Set returnfig=True when