import matplotlib.pyplot as plt #import matplotlib with the typical alias plt
ax #axis container of a subplot
ax.annotate() #allows to annotate values in chart
ax.annotate(xy=() , xytext(), arrowprops={}) #locates annotation and arrow
ax.bar() #creates a bar chart
ax.label #creates label legend in chart
ax.plot(my_data["x"],my_data["y"]) #sets the x and y axis of a plot
ax.set_xlabel("my_x_name") #names horizontal axis
ax.set_xticklabels([df.index , rotation = 90) #rotates xtick labels by 90 degreees
ax.set_ylabel("my_y_name") #names the vertical axis
ax.set_ylabel(color="") #sets colour of the vertical axis name
ax.set_title() #sets chart title
ax.tick_params() #tick setting in a chart
ax.tick_params("x",colors="") #set colour of vertical axis ticks
ax.tick_params("y",colors="") #set colour of vertical axis ticks
ax.twinx() #creates secondary y axis for the share x axis
.clf() #erases output charts
fig
fig.savefig() #saves a chart
fig.savefig("my_name.png") #saves a chart as png
fig.savefig("my_name.png", dpi=300) #saves a chart as png and sezs quality
fig.svfefig("my_name.jpg") #saves a chart as jpg
fig.savefig("my_name.png", quality=50) #saves a chart as jpg with a compression (1 to 100)
fig.savefig("my_name.svg") #saves a chart as vector graphics
fig.set_size_inches([w,h]) #set figure size in inches
.grid() #add grid lines
.hist() #plots a histogram
.legend() #creates a legends for labels
.legend(["labelA","labelB"]) #makes "labelA" and "labelB"
.plot() #plots a line chart
.subplot() #creates the containers fig and ax
.show() #shows a chart
.text() #adds text inside the chart
.title() #adds title to chart
.scatter() #plots a scatter plot
.xlabel() #labels horizontal axis
.xscale() #set the scale of the horizontal axis
.ylable() #labels vertical axis
.yticks() #change ticks on the virtical axis
.yticks(tick,label) #labels the ticks on the veritcal axis
.plot(
kind = "bar"
, title = "my_title" #creates chart's title
)
ax.bar(
my_data["x"]
, my_data["y"]
, label = "my_y_values" #use ax.legend() to activate labels
)
ax.bar(
my_data["x"]
, my_data["y2"], bottom = my_data["y1"] #makes a stacked bar chart
)
ax.bra(
my_data["x"]
, my_data["y3"], bottom = my_data["y1"] + my_data["y1"] #makes a stacked bar chart
)
ax.bar(
my_data["x"]
, my_data["y"]
, yerr = my_df["header"].std() #gives error bar on standard deviation
)
.plot(
kind = "line"
, x = "my_x_axis" #sets horizontal axis
, y = "my_y_axis" #sets vertical axis
, title = "my_title" #creates chart's title
, rot = n #rotates label by n degrees
, marker = "" #sets marker dot
, color ="" #sets colour
, linetyle ="" sets line style
, label = "" adds additional plot label in header
)
ax.errorbar(
my_df["xheader"]
, my_df["yheader"]
, yerr=my_df["my_std"] #adds error bar
)
.plot(
kind = "scatter"
, x = "my_x_axis" #sets horizontal axis
, y = "my_y_axis" #sets vertical axis
, title = "my_title" #creates chart's title
)
.scatter(
x = "my_x_axis" #sets horizontal axis
, y = "my_y_axis" #sets vertical axis
, alpha #from 0 for transaparent to 1 for opague
)
ax.scatter(
my_df["header1"] #sets x axis
, my_df["header2"] #sets y axis
, color = "red" #sets colour red
, label = "my label" #sets label
, c = my_df.index #sets a scale colour on the index
)
.hist(
bin = n #number of bins, preset to 10
, alpha #from 0 for transaparent to 1 for opague
)
ax.hist(
my_df["header"]
, label = "my_label" #set label, needs ax.legend() to be activated
, bin = n #number of bins, preset to 10
, bin = [ n, m, k, … ] #set bins via boundaries between
, histtype = "step" #sets type, with "bar" as standard
)
ax.boxplot(
my_df["xheader"]
, my_df["yheader"]
)
ax.subplot(n,m) #creates n * m plots in a grid of n rows and m colums
.ax.subplot(n,m, sharey=True) #has subplots have equal y axes each
ax.shape #shows (n,m) for a multiple plot of subplots
ax[n,m] #accesses a multiple plot of subplots
.annotate(
"my annotation text"
, xy=() #location to annotate
, xytext=() #location of text
, arrowprops={
"arrowstyle":"->"
, "color":"green"
}
) #arrow with the property descripton dictionary
ax.label #creates label legend in chart
.text() #adds text inside the chart
plt.style #there are different styles to chose from
plt.style.use("ggplot") #style "ggplot"
plt.style.use("default") #default style
fig, ax = plt.subplots()
ax.plot( my_df["header1"] , my_df["header2"] )
plt.show()
fig, ax = plt.subplots()
ax.plot(my_df.index, my_df["header1"], color="blue")
ax2 = ax.twinx()
ax2.plot(my_df.index, my_df["header2"], color="red")
plt.show()
def plot_timeseries(axes, x, y, colour, xlabel, ylabel):
axes.plot(x, y, color=colour)
axes.set_xlabel(xlabel)
axes.set_ylabel(ylabel, color=colour)
axes.tick_params('y', colors=colour)
fig, ax = plt.subplots()
plot_timeseries(ax, my_df.index, my_df["value1"], "blue", "Time", "Value1")
ax2 = ax.twinx()
plot_timeseries(ax2, my_df.index, my_df["value2"], "red", "Time", "Value2")
plt.show()
fig, ax = plt.subplots()
ax.bar("My_mean1", my_df["Header1"].mean(), yerr=my_df["Header1"].std())
ax.bar("My_mean2", my_df["Header2"].mean(), yerr=my_df["Header2"].std())
ax.set_ylabel("My_y_units")
plt.show()
fig, ax = plt.subplots()
ax.boxplot([my_df["Header1"],my_df["Header2"]])
ax.set_xticklabels(["My_header1","My_header2"])
ax.set_ylabel("My y unit")
plt.show()
fig, ax = plt.subplots()
for element in my_list:
my_df = my_data[my_data["Value"]==value]
ax.bar(element, my_df["header"].mean(),
yerr=my_df["header"].std())
ax.set_ylabel("Header")
ax.set_xticklabels(my_list, rotation=90)
plt.show()