I am trying to plot the below dataset as barplot cum pointplot using seaborn.
But the time-stamp in the x-axis labels shows additional zeroes at the end as shown below
The code I use is
import matplotlib.pyplot as plt
import seaborn as sns
fig, ax1 = plt.subplots()
# Plot the barplot
sns.barplot(x='Date', y=y_value, hue='Sentiment', data=mergedData1, ax=ax1)
# Assign y axis label for bar plot
ax1.set_ylabel('No of Feeds')
# Position the legen on the right side outside the box
plt.legend(loc=2, bbox_to_anchor=(1.1, 1), ncol=1)
# Create a dual axis
ax2 = ax1.twinx()
# Plot the ponitplot
sns.pointplot(x='Date', y='meanTRP', data=mergedData1, ax=ax2, color='r')
# Assign y axis label for point plot
ax2.set_ylabel('TRP')
# Hide the grid for secondary axis
ax2.grid(False)
# Give a chart title
plt.title(source+' Social Media Feeds & TRP for the show '+show)
# Automatically align the x axis labels
fig.autofmt_xdate()
fig.tight_layout()
Not sure what is going wrong. Please help me with this. Thanks
Method 1: To set the axes label in the seaborn plot, we use matplotlib.axes.Axes.set () function from the matplotlib library of python. xlabel : str- The label text for the x-axis. ylabel : str- The label text for the y-axis. Returns: It will change the x-axis and y-axis labels.
Axes Limits are the limits to the axes’ values, which are used to filter for a required value on axes. Here, In this article, the content goes from setting the axes labels, axes limits, and both at a time. In the end, you will be able to learn how to set axes labels & limits in a Seaborn plot.
Make sure to assign the axes-level object while creating the plot. This object is then used for setting the title and labels as shown below. We can also change the axis labels and set the plot title with the matplotlib.pyplot object using xlabel (), ylabel () and title () functions.
To create a line plot with Seaborn we can use the lineplot method, as previously mentioned. Here’s a working example plotting the x variable on the y-axis and the Day variable on the x-axis: Here we started with the simplest possible line graph using Seaborn’s lineplot.
Easiest solution is to split the text at the letter "T" as the rest is probably not needed.
ax.set_xticklabels([t.get_text().split("T")[0] for t in ax.get_xticklabels()])
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