I have an existing plot that was created with pandas like this:

```
df['myvar'].plot(kind='bar')
```

The y axis is format as float and I want to change the y axis to percentages. All of the solutions I found use ax.xyz syntax and **I can only place code below the line above that creates the plot** (I cannot add ax=ax to the line above.)

**How can I format the y axis as percentages without changing the line above?**

Here is the solution I found **but requires that I redefine the plot**:

```
import matplotlib.pyplot as plt
import numpy as np
import matplotlib.ticker as mtick
data = [8,12,15,17,18,18.5]
perc = np.linspace(0,100,len(data))
fig = plt.figure(1, (7,4))
ax = fig.add_subplot(1,1,1)
ax.plot(perc, data)
fmt = '%.0f%%' # Format you want the ticks, e.g. '40%'
xticks = mtick.FormatStrFormatter(fmt)
ax.xaxis.set_major_formatter(xticks)
plt.show()
```

Link to the above solution: Pyplot: using percentage on x axis

This question is related to
`python`

`pandas`

`matplotlib`

`plot`

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`

, `symbol`

. `xmax`

allows you to set the value that corresponds to 100% on the axis. This is nice if you have data from 0.0 to 1.0 and you want to display it from 0% to 100%. Just do `PercentFormatter(1.0)`

.

The other two parameters allow you to set the number of digits after the decimal point and the symbol. They default to `None`

and `'%'`

, respectively. `decimals=None`

will automatically set the number of decimal points based on how much of the axes you are showing.

**Update**

`PercentFormatter`

was introduced into Matplotlib proper in version 2.1.0.

- programming a servo thru a barometer
- Is there a way to view two blocks of code from the same file simultaneously in Sublime Text?
- python variable NameError
- Why my regexp for hyphenated words doesn't work?
- Comparing a variable with a string python not working when redirecting from bash script
- is it possible to add colors to python output?
- Get Public URL for File - Google Cloud Storage - App Engine (Python)
- Real time face detection OpenCV, Python
- xlrd.biffh.XLRDError: Excel xlsx file; not supported
- Could not load dynamic library 'cudart64_101.dll' on tensorflow CPU-only installation
- Upgrade to python 3.8 using conda
- Unable to allocate array with shape and data type
- How to fix error "ERROR: Command errored out with exit status 1: python." when trying to install django-heroku using pip
- How to prevent Google Colab from disconnecting?
- "UserWarning: Matplotlib is currently using agg, which is a non-GUI backend, so cannot show the figure." when plotting figure with pyplot on Pycharm
- How to fix 'Object arrays cannot be loaded when allow_pickle=False' for imdb.load_data() function?
- "E: Unable to locate package python-pip" on Ubuntu 18.04
- Tensorflow 2.0 - AttributeError: module 'tensorflow' has no attribute 'Session'
- Jupyter Notebook not saving: '_xsrf' argument missing from post
- How to Install pip for python 3.7 on Ubuntu 18?
- Python: 'ModuleNotFoundError' when trying to import module from imported package
- OpenCV TypeError: Expected cv::UMat for argument 'src' - What is this?
- Requests (Caused by SSLError("Can't connect to HTTPS URL because the SSL module is not available.") Error in PyCharm requesting website
- How to setup virtual environment for Python in VS Code?
- Pylint "unresolved import" error in Visual Studio Code
- Pandas Merging 101
- Numpy, multiply array with scalar
- What is the meaning of "Failed building wheel for X" in pip install?
- Selenium: WebDriverException:Chrome failed to start: crashed as google-chrome is no longer running so ChromeDriver is assuming that Chrome has crashed
- Could not install packages due to an EnvironmentError: [Errno 13]
- OpenCV !_src.empty() in function 'cvtColor' error
- ConvergenceWarning: Liblinear failed to converge, increase the number of iterations
- How to downgrade python from 3.7 to 3.6
- I can't install pyaudio on Windows? How to solve "error: Microsoft Visual C++ 14.0 is required."?
- Iterating over arrays in Python 3
- How do I install opencv using pip?
- How do I install Python packages in Google's Colab?
- How do I use TensorFlow GPU?
- How to upgrade Python version to 3.7?
- How to resolve TypeError: can only concatenate str (not "int") to str
- How can I install a previous version of Python 3 in macOS using homebrew?
- Flask at first run: Do not use the development server in a production environment
- TypeError: only integer scalar arrays can be converted to a scalar index with 1D numpy indices array
- What is the difference between Jupyter Notebook and JupyterLab?
- Pytesseract : "TesseractNotFound Error: tesseract is not installed or it's not in your path", how do I fix this?
- Could not install packages due to a "Environment error :[error 13]: permission denied : 'usr/local/bin/f2py'"
- How do I resolve a TesseractNotFoundError?
- Trying to merge 2 dataframes but get ValueError
- Authentication plugin 'caching_sha2_password' is not supported
- Python Pandas User Warning: Sorting because non-concatenation axis is not aligned
- [Move to Format y axis as percent]

- xlrd.biffh.XLRDError: Excel xlsx file; not supported
- Pandas Merging 101
- How to increase image size of pandas.DataFrame.plot in jupyter notebook?
- Trying to merge 2 dataframes but get ValueError
- Python Pandas User Warning: Sorting because non-concatenation axis is not aligned
- How to show all of columns name on pandas dataframe?
- Pandas/Python: Set value of one column based on value in another column
- Python Pandas - Find difference between two data frames
- Pandas get the most frequent values of a column
- Python convert object to float
- Python: Pandas pd.read_excel giving ImportError: Install xlrd >= 0.9.0 for Excel support
- Pandas: ValueError: cannot convert float NaN to integer
- How to create a stacked bar chart for my DataFrame using seaborn?
- LabelEncoder: TypeError: '>' not supported between instances of 'float' and 'str'
- Display/Print one column from a DataFrame of Series in Pandas
- How to calculate 1st and 3rd quartiles?
- Counting unique values in a column in pandas dataframe like in Qlik?
- Binning column with python pandas
- convert array into DataFrame in Python
- Selection with .loc in python
- Set value to an entire column of a pandas dataframe
- Pandas create empty DataFrame with only column names
- Python: pandas merge multiple dataframes
- 'DataFrame' object has no attribute 'sort'
- Remove Unnamed columns in pandas dataframe
- Convert float64 column to int64 in Pandas
- Understanding inplace=True
- How to select rows with NaN in particular column?
- How to print a specific row of a pandas DataFrame?
- Pandas rename column by position?
- re.sub erroring with "Expected string or bytes-like object"
- Python Pandas iterate over rows and access column names
- Display rows with one or more NaN values in pandas dataframe
- Python "TypeError: unhashable type: 'slice'" for encoding categorical data
- Seaborn Barplot - Displaying Values
- ValueError: Wrong number of items passed - Meaning and suggestions?
- How to get row number in dataframe in Pandas?
- How to install pandas from pip on windows cmd?
- Pandas convert string to int
- Convert list into a pandas data frame
- Use .corr to get the correlation between two columns
- Why isn't this code to plot a histogram on a continuous value Pandas column working?
- How to add title to seaborn boxplot
- ValueError: Length of values does not match length of index | Pandas DataFrame.unique()
- How to save a new sheet in an existing excel file, using Pandas?
- matplotlib: plot multiple columns of pandas data frame on the bar chart
- Convert List to Pandas Dataframe Column
- TypeError: 'DataFrame' object is not callable
- Set order of columns in pandas dataframe
- Python Pandas - Missing required dependencies ['numpy'] 1
- [Move to Format y axis as percent]

- "UserWarning: Matplotlib is currently using agg, which is a non-GUI backend, so cannot show the figure." when plotting figure with pyplot on Pycharm
- How to increase image size of pandas.DataFrame.plot in jupyter notebook?
- How to create a stacked bar chart for my DataFrame using seaborn?
- How to display multiple images in one figure correctly?
- Edit seaborn legend
- How to hide axes and gridlines in Matplotlib (python)
- How to set x axis values in matplotlib python?
- How to specify legend position in matplotlib in graph coordinates
- Python "TypeError: unhashable type: 'slice'" for encoding categorical data
- Seaborn Barplot - Displaying Values
- Purpose of "%matplotlib inline"
- How to make two plots side-by-side using Python?
- Why plt.imshow() doesn't display the image?
- Add Legend to Seaborn point plot
- Change line width of lines in matplotlib pyplot legend
- How to add title to seaborn boxplot
- How to plot vectors in python using matplotlib
- How to plot an array in python?
- matplotlib: plot multiple columns of pandas data frame on the bar chart
- TypeError: 'DataFrame' object is not callable
- Plotting images side by side using matplotlib
- How to change the plot line color from blue to black?
- Pandas dataframe groupby plot
- FutureWarning: elementwise comparison failed; returning scalar, but in the future will perform elementwise comparison
- Matplotlib - How to plot a high resolution graph?
- Python & Matplotlib: Make 3D plot interactive in Jupyter Notebook
- _tkinter.TclError: no display name and no $DISPLAY environment variable
- matplotlib: how to draw a rectangle on image
- Plotting a python dict in order of key values
- Hide axis values but keep axis tick labels in matplotlib
- How to draw a line with matplotlib?
- TypeError: Invalid dimensions for image data when plotting array with imshow()
- What's the fastest way of checking if a point is inside a polygon in python
- How to make inline plots in Jupyter Notebook larger?
- matplotlib error - no module named tkinter
- Fine control over the font size in Seaborn plots for academic papers
- %matplotlib line magic causes SyntaxError in Python script
- How can I plot a confusion matrix?
- Plotting lines connecting points
- Display an image with Python
- Why do many examples use `fig, ax = plt.subplots()` in Matplotlib/pyplot/python
- Python: How to increase/reduce the fontsize of x and y tick labels?
- Plot a horizontal line using matplotlib
- Plotting a 2D heatmap with Matplotlib
- How to set the range of y-axis for a seaborn boxplot?
- How to plot a histogram using Matplotlib in Python with a list of data?
- Modify the legend of pandas bar plot
- Add colorbar to existing axis
- How to save a Seaborn plot into a file
- How to rotate x-axis tick labels in Pandas barplot
- [Move to Format y axis as percent]

- Fine control over the font size in Seaborn plots for academic papers
- Why do many examples use `fig, ax = plt.subplots()` in Matplotlib/pyplot/python
- Modify the legend of pandas bar plot
- Format y axis as percent
- Simple line plots using seaborn
- Plot bar graph from Pandas DataFrame
- Plotting multiple lines, in different colors, with pandas dataframe
- Plotting in a non-blocking way with Matplotlib
- What does the error "arguments imply differing number of rows: x, y" mean?
- matplotlib get ylim values
- How to plot a function curve in R
- How to add title to subplots in Matplotlib?
- How to plot ROC curve in Python
- Change grid interval and specify tick labels in Matplotlib
- Reduce size of legend area in barplot
- Error in plot.new() : figure margins too large, Scatter plot
- Python how to plot graph sine wave
- Plot mean and standard deviation
- Code for best fit straight line of a scatter plot in python
- Plotting a list of (x, y) coordinates in python matplotlib
- Error in plot.window(...) : need finite 'xlim' values
- multiple plot in one figure in Python
- How to combine 2 plots (ggplot) into one plot?
- Adjust plot title (main) position
- Stacked Bar Plot in R
- how to draw directed graphs using networkx in python?
- Overlay normal curve to histogram in R
- Plot a line graph, error in xy.coords(x, y, xlabel, ylabel, log) : 'x' and 'y' lengths differ
- Plot Normal distribution with Matplotlib
- Plotting multiple time series on the same plot using ggplot()
- Add missing dates to pandas dataframe
- Adding a legend to PyPlot in Matplotlib in the simplest manner possible
- How to plot time series in python
- How to plot two columns of a pandas data frame using points?
- Create own colormap using matplotlib and plot color scale
- Colorplot of 2D array matplotlib
- R barplot Y-axis scale too short
- Plot a bar using matplotlib using a dictionary
- 3D Plotting from X, Y, Z Data, Excel or other Tools
- How to set xlim and ylim for a subplot in matplotlib
- How to export plots from matplotlib with transparent background?
- How can I make a "color map" plot in matlab?
- Set the intervals of x-axis using r
- Label points in geom_point
- Add error bars to show standard deviation on a plot in R
- Plotting of 1-dimensional Gaussian distribution function
- Plot multiple lines (data series) each with unique color in R
- How to change legend title in ggplot
- Plot multiple boxplot in one graph
- Increase distance between text and title on the y-axis
- [Move to Format y axis as percent]