I'm trying to save a pandas.DataFrame.boxplot
variable to a image to use it with a Qt widget, but I don't know how to convert this variable. I have this code:
import matplotlib.pyplot as plt
from pandas import DataFrame
import numpy as np
df = DataFrame(np.random.rand(10,5))
plt.figure();
bp = df.boxplot()
And Spyder shows it:
Are there instructions to do it automatically within the code?
Suppose you have multiple figures and you want to save them independently when you want in the code: make sure you can access it by a unique name:
fig100 = figure()
outputBoxplot100 = df_100.boxplot(column=['1', '2', '4', '5', '8'])
plt.title("100 MHz")
fig150 = figure()
outputBoxplot150 = df_150.boxplot(column=['1', '2', '4', '5', '8'])
plt.title("150 MHz")
# do other stuff
fig100.savefig("test100.svg", format="svg")
fig150.savefig("test150.svg", format="svg")
In this case, I would change your code in:
import matplotlib.pyplot as plt
from pandas import DataFrame
import numpy as np
df = DataFrame(np.random.rand(10,5))
myFig = plt.figure();
bp = df.boxplot()
myFig.savefig("myName.svg", format="svg")
The result will be a saved file named "myName.svg":
Are you looking for a standard image format?
If so this will do the trick:
import matplotlib.pyplot as plt
plt.savefig()
docs: https://matplotlib.org/devdocs/api/_as_gen/matplotlib.pyplot.savefig.html
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