xticks

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()

Matplotlib Line vs. Bar plot DateTime axis formatting

ⅰ亾dé卋堺 提交于 2021-02-11 12:29:30
问题 I have a DataFrame with a DateTime index: import pandas as pd from random import randrange dates = pd.date_range(start="2020-02-01",end='2020-04-18',freq='1d') df = pd.DataFrame(index=dates,data=[randrange(10000) for i in range(78)] Now when I plot the data as a line plot, matplotlib produces a nicely formatted x axis: df.plot(figsize=(12,4)) However, if instead I do a bar plot, I now get something quite horrible: df.plot(kind='bar',figsize=(12,4)), This is quite disconcerting, as it is the

How do I plot hours and minutes when they are in different pandas columns?

筅森魡賤 提交于 2020-07-18 21:04:59
问题 I have a pandas' dataframe like: hour minute cnt 0 0 904890 0 30 880374 1 0 848198 1 30 816488 2 0 791761 I would like to plot cnt using minute as minor ticks, and hour as major tick in matplotlib. I've tried several things but they didn't work. Here's one: fig, ax = plt.subplots(figsize=(8,5)) df.plot(kind='line', y='cnt', ax=ax) ax.set_xticks(df['minute']) ax.set_xticklabels(df['minute']) I'd like my x-axis to look like |---+---+---+---+---+---+---+---| 0 15 30 45 0 30 45 0 15 0 1 2 ...

Date format issues in plot ticks with matplotlib.dates (and datestr2num)

岁酱吖の 提交于 2020-06-28 08:39:42
问题 I'm using matplotlib.dates to plot a bar chart with instances occurring on specific dates (presented as a list of strings), and using matplotlib.dates.datestr2num to display two sets of data per date (as per the top answer in Python matplotlib multiple bars). However, for dates below the 12th day of the month, the plot is interpreting the dates in MM/DD/YY format, while for dates above the 12th day of the month it is interpreting the dates as DD/MM/YY, causing the data to jump around the plot