How do I tell Matplotlib to create a second (new) plot, then later plot on the old one?

If you find yourself doing things like this regularly it may be worth investigating the object-oriented interface to matplotlib. In your case: import matplotlib.pyplot as plt import numpy as np x = np.arange(5) y = np.exp(x) fig1, ax1 = plt.subplots() ax1.plot(x, y) ax1.set_title(“Axis 1 title”) ax1.set_xlabel(“X-label for axis 1”) z = np.sin(x) fig2, (ax2, ax3) … Read more

Plotting time in Python with Matplotlib

Update: This answer is outdated since matplotlib version 3.5. The plot function now handles datetime data directly. See https://matplotlib.org/3.5.1/api/_as_gen/matplotlib.pyplot.plot_date.html The use of plot_date is discouraged. This method exists for historic reasons and may be deprecated in the future. datetime-like data should directly be plotted using plot. If you need to plot plain numeric data as … Read more

What is the difference between pylab and pyplot? [duplicate]

This wording is no longer in the documentation. Use of the pylab import is now discouraged and the OO interface is recommended for most non-interactive usage. From the documentation, the emphasis is mine: Matplotlib is the whole package; pylab is a module in matplotlib that gets installed alongside matplotlib; and matplotlib.pyplot is a module in … Read more

Format y axis as percent

This is a few months late, but I have created PR#6251 with matplotlib to add a new PercentFormatter class. With this class you just need one line to reformat your axis (two if you count the import of matplotlib.ticker): import … import matplotlib.ticker as mtick ax = df[‘myvar’].plot(kind=’bar’) ax.yaxis.set_major_formatter(mtick.PercentFormatter()) PercentFormatter() accepts three arguments, xmax, decimals, … Read more

Add missing dates to pandas dataframe

You could use Series.reindex: import pandas as pd idx = pd.date_range(’09-01-2013′, ’09-30-2013′) s = pd.Series({’09-02-2013′: 2, ’09-03-2013′: 10, ’09-06-2013′: 5, ’09-07-2013′: 1}) s.index = pd.DatetimeIndex(s.index) s = s.reindex(idx, fill_value=0) print(s) yields 2013-09-01 0 2013-09-02 2 2013-09-03 10 2013-09-04 0 2013-09-05 0 2013-09-06 5 2013-09-07 1 2013-09-08 0 …

Label points in geom_point

Use geom_text , with aes label. You can play with hjust, vjust to adjust text position. ggplot(nba, aes(x= MIN, y= PTS, colour=”green”, label=Name))+ geom_point() +geom_text(hjust=0, vjust=0) EDIT: Label only values above a certain threshold: ggplot(nba, aes(x= MIN, y= PTS, colour=”green”, label=Name))+ geom_point() + geom_text(aes(label=ifelse(PTS>24,as.character(Name),”)),hjust=0,vjust=0)

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)