0

I am currently making a bunch of graphs for my thesis. I have some outliers in a few of my graphs that distend the y axis making the main chunk of data hard to read. I want to make a break in the y axis so I can make the graph easier to read, but I don't know how. Here is my code (the commented outlines are lines I have used when making other box plots, mostly for sorting out y-axis tick issues).

import openpyxl
import pandas as pd
import matplotlib.pyplot as plt
import seaborn as sns
import numpy as np

#extracting data#
wb = openpyxl.load_workbook(data.xlsx)
wow = wb.sheetnames
col=wb['Sheet1']
row=col.max_row
column=col.max_column
wowa = []
for i in range(1,row+1):
    for j in range(1,column+1):
        wowa.append(col.cell(i,j).value)
print(wowa)

#df#
df = pd.DataFrame(wowa, columns= ['Bond strain'])
df.index += 1
print(df)

#colour#
sns.color_palette('Spectral', as_cmap=True)
hey = (np.random.random(), np.random.random(), np.random.random())
sns.set_style('whitegrid', {'axes.grid':True, 'font.sans-serif':'Arial'})

#plt#
#fig, ax = plt.subplots()
sns.boxplot(y='Bond strain', data=df, color=hey)
#ax.yaxis.set_ticks(np.arange(2, 15, 1))
#ax.yaxis.set_major_formatter(ticker.FormatStrFormatter('%0.01f'))
plt.show()

The resulting graph

I tried to use the method from the matplotlib website, but I couldn't get it to work, I don't know if its because I am using seaborn or because its a boxplot. This is my first time making graphs using python so I am a bit slow.

chikun420
  • 1
  • 1
  • 2
    Have you tried the package [brokenaxes](https://stackoverflow.com/questions/5656798/is-there-a-way-to-make-a-discontinuous-axis-in-matplotlib)? – Tranbi Apr 18 '23 at 13:34
  • @Tranbi I looked at it but I didn't know how to implement it into my code :( – chikun420 Apr 18 '23 at 13:59

0 Answers0