In the example below, ax1.bar creates a customized bar plot in the first plot, and ax2.scatter creates a customized scatter in the second plot. format(x) return s ax.t_major_formatter(number_formatter) ax.t_major_formatter(number_formatter) #set chart source and copyright plt.annotate( 'Source: UNHCR Refugee Data Finder', ( 0, 0), ( 0, - 40), xycoords = 'axes fraction', textcoords = 'offset points', va = 'top', color = '#666666', fontsize = 9) plt.annotate( '©UNHCR, The UN Refugee Agency', ( 0, 0), ( 0, - 50), xycoords = 'axes fraction', textcoords = 'offset points', va = 'top', color = '#666666', fontsize = 9) #adjust chart margin and layout fig.tight_layout() #show chart plt. x: x y: y fmt: label: Matplotlib.pyplot import matplotlib.pyplot as plt import numpy as np x np.linspace(0, 2np.pi, 100) y np.sin(x) plt.plot(x, y, '-r', label'sin (x)') plt.xlabel('X') plt.ylabel('Y') plt.legend(loc'upper left') plt.title('A Sin Graph') plt. Once you have your fig and two axis objects defined, you can add data to each axis and define the plot with unique characteristics. The Python matplotlib pyplot module has a function that will draw or generate a scatter plot, and the basic syntax to draw it is (x, y) x: list of arguments that represents the X-axis. # import libraries import matplotlib.pyplot as plt import pandas as pd () #load data set df = pd.read_csv( '') #compute data array for plotting x = df y = df label = df #plot the chart fig, ax = plt.subplots() ax.scatter(x, y, s = 30) # Loop for annotation of all points for i in range( len(x)): plt.annotate(label, (x, y), textcoords = "offset points", xytext =( 0, 5), ha = 'left') #set chart title ax.set_title( 'Comparison of refugee and IDP population by region | 2021') #set axis label ax.set_xlabel( 'Number of refugees (millions)') ax.set_ylabel( 'Number of IDPs (millions)') #format axis tick labels def number_formatter(x, pos): if x >= 1e6: s = ' '. Format y axis as percent Ask Question Asked 7 years, 11 months ago Modified 4 months ago Viewed 303k times 220 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.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |