I used df.plot() to get this plot:
I want to change the marker style to circles to make my plot look like this:
Also, is there a way to display the y axis value above each marker point?
To change the index values we need to use the set_index method which is available in pandas allows specifying the indexes. where, inplace parameter accepts True or False, which specifies that change in index is permanent or temporary. True indicates that change is Permanent.
melt() function is used to reshape a DataFrame from a wide to a long format. It is useful to get a DataFrame where one or more columns are identifier variables, and the other columns are unpivoted to the row axis leaving only two non-identifier columns named variable and value by default.
orient: String value, ('dict', 'list', 'series', 'split', 'records', 'index') Defines which dtype to convert Columns(series into). For example, 'list' would return a dictionary of lists with Key=Column name and Value=List (Converted series).
The marker is pretty easy. Just use df.plot(marker='o')
.
Adding the y axis value above the points is a bit more difficult, as you'll need to use matplotlib directly, and add the points manually. The following is an example of how to do this:
import numpy as np
import pandas as pd
from matplotlib import pylab
z=pd.DataFrame( np.array([[1,2,3],[1,3,2]]).T )
z.plot(marker='o') # Plot the data, with a marker set.
pylab.xlim(0,3) # Change the axes limits so that we can see the annotations.
pylab.ylim(0,4)
ax = pylab.gca()
for i in z.index: # iterate through each index in the dataframe
for v in z.ix[i].values: # and through each value being plotted at that index
# annotate, at a slight offset from the point.
ax.annotate(str(v),xy=(i,v), xytext=(5,5), textcoords='offset points')
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With