#106 Seaborn style on matplotlib plot

Matplotlib allows to make absolutely any type of chart, but its style does not look very great. It is possible to benefit the seaborn library style really easily: just the load the seaborn library before your plot!


# library and dataset
from matplotlib import pyplot as plt
import pandas as pd
import numpy as np

# Create data
df=pd.DataFrame({'x': range(1,101), 'y': np.random.randn(100)*15+range(1,101), 'z': (np.random.randn(100)*15+range(1,101))*2 })

# plot with matplotlib
plt.plot( 'x', 'y', data=df, marker='o', color='mediumvioletred')
plot.show()

# Just load seaborn and the chart looks better:
import seaborn as sns
plt.plot( 'x', 'y', data=df, marker='o', color='mediumvioletred')
plt.show()

 

 

  • Sponsors

  • 1 comment

    • “Matplotlib allows to make absolutely any type of chart, but its style does not look very great. It is possible to benefit the seaborn library style really easily: *just the load the seaborn library* before your plot!”

      The Hell?

      No. You actually need to USE the seaborn library for it to do anything; simply importing it does precisely nothing to your plot. I ran this script three times just to make absolutely sure there wasn’t something magical about this library alluding me, but no, running the script you have gives nothing but a standard matplotlib plot. Twice.

      With an error! Cuz oh by the way “plot.show()” throws an error because “plot” is undefined; you need to say “plt.” But I’m not shocked there’s a problem with your matplotlib code since you obvious didn’t bother running both to demonstrate the difference between the two code segments.

      To use seaborn you need to actually tell your IDE to use something from it, which I learned how to do from some other site, NO thanks to you. What idiocy.

      Reply

    Leave a Reply

    Your email address will not be published.