matplotlib

how to highlight weekends in matplotlib plots?

人走茶凉 提交于 2021-02-15 07:02:06
问题 For a simple time series: import pandas as pd df = pd.DataFrame({'dt':['2020-01-01', '2020-01-02', '2020-01-04', '2020-01-05', '2020-01-06'], 'foo':[1,2, 4,5,6]}) df['dt'] = pd.to_datetime(df.dt) df['dt_label']= df['dt'].dt.strftime('%Y-%m-%d %a') df = df.set_index('dt') #display(df) df['foo'].plot() x =plt.xticks(ticks=df.reset_index().dt.values, labels=df.dt_label, rotation=90, horizontalalignment='right') How can I highlight the x-axis labels for weekends? edit Pandas Plots: Separate color

Strange behavior of MultipleLocator() with subplots

☆樱花仙子☆ 提交于 2021-02-15 06:55:33
问题 I'm having trouble with this piece of code: import matplotlib.pyplot as plt from matplotlib.ticker import MultipleLocator, FormatStrFormatter majorLocator = MultipleLocator(0.1) majorFormatter = FormatStrFormatter('%2.1f') fig = plt.figure() axes = [] for i in range(4): axes.append(fig.add_subplot(2,2,i+1)) for ax in axes: ax.yaxis.set_major_locator(majorLocator) ax.yaxis.set_major_formatter(majorFormatter) ax.set_ylim(0,1) axes[-1].set_ylim(1,2) #If you comment this line all works fine. plt

Strange behavior of MultipleLocator() with subplots

陌路散爱 提交于 2021-02-15 06:55:12
问题 I'm having trouble with this piece of code: import matplotlib.pyplot as plt from matplotlib.ticker import MultipleLocator, FormatStrFormatter majorLocator = MultipleLocator(0.1) majorFormatter = FormatStrFormatter('%2.1f') fig = plt.figure() axes = [] for i in range(4): axes.append(fig.add_subplot(2,2,i+1)) for ax in axes: ax.yaxis.set_major_locator(majorLocator) ax.yaxis.set_major_formatter(majorFormatter) ax.set_ylim(0,1) axes[-1].set_ylim(1,2) #If you comment this line all works fine. plt

Is it possible to draw a broken axis graph with seaborn?

假如想象 提交于 2021-02-15 06:14:53
问题 I need to draw a broken x axis graph (e.g. the graph below) with existing data, my question is whether it's possible to use seaborn APIs to do that? 回答1: Not as pretty as I'd like but works. %matplotlib inline # If you are running this in a Jupyter Notebook. import seaborn as sns import numpy as np import matplotlib.pyplot as plt x = np.linspace(0, 20, 500) y = np.sin(x) f, (ax1, ax2) = plt.subplots(ncols=2, nrows=1, sharey=True) ax = sns.tsplot(time=x, data=y, ax=ax1) ax = sns.tsplot(time=x,

Highlighting weekends in small multiples

江枫思渺然 提交于 2021-02-15 05:33:17
问题 How can I highlight weekends in a small multiples? I've read different threads (e.g. (1) and (2)) but couldn't figure out how to implement it into my case, since I work with small multiples where I iterate through the DateTimeIndex to every month (see code below figure). My data Profiles is for this case a time-series of 2 years with an interval of 15min (i.e. 70080 datapoints). However, weekend days occuring at the end of the month and therefore generate an error; in this case: IndexError:

How to set two time formatters in matplotlib?

China☆狼群 提交于 2021-02-15 05:27:07
问题 This chart is built by Excel. How can I do the same using matplotlib? I mean how to add two formatters: years months. Now i use something like this: fig, ax = plt.subplots(1,1) ax.margins(x=0) ax.plot(list(df['Date']), list(df['Value']), color="g") ax.xaxis.set_major_locator(matplotlib.dates.YearLocator()) ax.xaxis.set_major_formatter(matplotlib.dates.DateFormatter('%Y')) plt.text(df["Date"].iloc[-1], df["Value"].iloc[-1], df["Value"].iloc[-1]) plt.title(title) plt.get_current_fig_manager()

How to set two time formatters in matplotlib?

孤者浪人 提交于 2021-02-15 05:26:22
问题 This chart is built by Excel. How can I do the same using matplotlib? I mean how to add two formatters: years months. Now i use something like this: fig, ax = plt.subplots(1,1) ax.margins(x=0) ax.plot(list(df['Date']), list(df['Value']), color="g") ax.xaxis.set_major_locator(matplotlib.dates.YearLocator()) ax.xaxis.set_major_formatter(matplotlib.dates.DateFormatter('%Y')) plt.text(df["Date"].iloc[-1], df["Value"].iloc[-1], df["Value"].iloc[-1]) plt.title(title) plt.get_current_fig_manager()

Discrete Color Bar with Tick labels in between colors

限于喜欢 提交于 2021-02-15 04:55:11
问题 I am trying to plot some data with a discrete color bar. I was following the example given (https://gist.github.com/jakevdp/91077b0cae40f8f8244a) but the issue is this example does not work 1-1 with different spacing. For example, the spacing in the example in the link is for only increasing by 1 but my data is increasing by 0.5. You can see the output from the code I have.. Any help with this would be appreciated. I know I am missing something key here but cant figure it out. import

Discrete Color Bar with Tick labels in between colors

大兔子大兔子 提交于 2021-02-15 04:52:09
问题 I am trying to plot some data with a discrete color bar. I was following the example given (https://gist.github.com/jakevdp/91077b0cae40f8f8244a) but the issue is this example does not work 1-1 with different spacing. For example, the spacing in the example in the link is for only increasing by 1 but my data is increasing by 0.5. You can see the output from the code I have.. Any help with this would be appreciated. I know I am missing something key here but cant figure it out. import

Plotting with scientific axis, changing the number of significant figures

不问归期 提交于 2021-02-15 03:51:15
问题 I am making the following plot in matplotlib, using amongst other things plt.ticklabel_format(axis='y',style='sci',scilimits=(0,3)) . This yields a y-axis as so: Now the problem is that I want the y-axis to have ticks from [0, -2, -4, -6, -8, -12] . I have played around with the scilimits but to no avail. How can one force the ticks to only have one significant figure and no trailing zeros, and be floats when required? MWE added below: import matplotlib.pyplot as plt import numpy as np t = np