matplotlib grid setting (python) - matplotlib

I made some changes of matplotlib settings and can't figure out how to put it back. it would be great if you can help me out!
original settings
image that i see now

You question lacks relevant information such as exactly what did you change. In any case something like this should solve your problem:
import matplotlib as mpl
mpl.rcParams.update(mpl.rcParamsDefault)

Try this:
import matplotlib.pyplot as plt
print plt.style.available
which will give you the list of available styles on your machine ('classic','seaborn', etc).
From here you can set which existing plot style you want to use with
plt.style.use('classic')

Related

How do I use a heatmap with vue highcharts?

I tried using heatmap as the chart type but I am getting error 17. I am using vue-highcharts and wondering how I can fix this proble. I looked online and it seems that I may have to import it and use it. Can anyone show me how to do that because I can't find any documentation on it?
import HighCharts from 'highcharts'
import heatmap from 'highcharts/modules/heatmap';
heatmap(HighCharts);
These are the import statements for it to work.

How to make figure legends and ticks visible in JupyterLab dark theme?

When using JupyterLab (Version 0.32.0) dark theme, figure ticks and legends are invisible because the foreground and background colors are very close. How to make them visible?
Following are some screenshots for illustration:
Plotting code:
import matplotlib.pyplot as plt
%matplotlib inline
plt.subplot()
plt.plot([1,2,3], label="test1")
plt.plot([3,2,1], label="test2")
plt.legend(bbox_to_anchor=(1.05, 1), loc=2,
frameon=False)
Output figure in the light theme:
The same output figure in the dark theme:
Notes:
This question has been asked multiple times in Github Issues of both JupyterLab and Matplotlib, and it has been answered by telamonian and blink1073. I repost and re-answer the question here for easier lookup for the answer.
According to issue 3855 of JupyterLab, upcoming versions may fix this issue.
Just to quote telamonian and blink1073's manual workaround here:
plt.style.use('dark_background')
Following is a short demo:
Code:
import matplotlib.pyplot as plt
%matplotlib inline
plt.style.use('dark_background')
plt.plot(list(range(10)), list(range(10)))

Trying to view decision tree in my notebook

I am trying to scale my decision tree to fit notebook but it appears not to scale properly. I have to keep scrolling for a better view. Can I please have some help on how to fix this. Attach is a pic of how it looks like.
from graphviz import Source
from sklearn import tree
from IPython.display import SVG
graph = Source( tree.export_graphviz(dt_classifier, out_file=None, feature_names=X.columns))
SVG(graph.pipe(format='svg'))
Perhaps it's not relevant any more, since this question has been open for about six months now. However, I just stumbled into it, as apparently 83 other readers, and I just crafted my way around this. The easy way is to use the pydot package (pip install pydot), and then add the default size. I have also been using %matplotlib inline so that it displays nicely within the notebook but without using the svg module. With your example:
%matplotlib inline
from graphviz import Source
from sklearn import tree
import pydot
dot_data = tree.export_graphviz(dt_classifier, out_file=None, feature_names=X.columns))
pdot = pydot.graph_from_dot_data(dot_data)
# Access element [0] because graph_from_dot_data actually returns a list of DOT elements.
pdot[0].set_graph_defaults(size = "\"15,15\"")
graph = Source(pdot[0].to_string())
graph
I also added rotate=True to export_graphviz so that it displays in horizontal style, the root of the tree is directly visible, and is easier to follow. Of course, you can play around with size so as to reach something that is acceptable for you.

Is style a module of matplotlib or matplotlib.pyplot?

Reading the matplotlib documentation, it looks like style is a module of matplotlib (matplotlib.style).
However, I've seen this code:
matplotlib.pyplot.style.use('seaborn')
I don't understand how the style module can be associated with (and called from) the matplotlib.pyplot module.
Matplotlib has a module style. This can be imported like
from matplotlib import style
The above line is also present inside the pyplot.py.
style is thus in the namespace of pyplot and you can do
matplotlib.pyplot.style.use("some_style")

pydev autocomplete for matplotlib

Here is the code I write in pydev combined with eclipse.
import matplotlib.pyplot as plt
fig=plt.figure()
as I know, 'fig' is a instance of 'matplotlib.Figure' class,when I write :
fig.
it seems pydev can't provide method calltip for fig. I cannot figure out what's going on, since for other module , like numpy, it works well.by the way, if i use a matlab-like interface, for example,
plt.plot()
pydev does provide the calltip for function arguments.
is there a way to solve this problem? I will appreciate it if anyone give a solution .
Forgive my poor english:-D
fig is an instance of matplotlib.figure.Figure so what you can do is importing import matplotlib.figure and creating an instance of that. Then, writing fig to the editor, you should get the tooltip you want.
The following is a screenshot from Spyder, so I haven't actually tested it in pydev.
I am not aware of any other possibility. The reason is that for the requested functionality to work the editor would need to load all kinds of modules, which are not actually imported in the script.
The issue is that some cases are too dynamic for PyDev to know about the actual type of the object that some method returns (which appears to be the case).
If you know the type, you can manually type it locally.
i.e.: Add the comment:
#: :type fig: matplotlib.figure.Figure
right before the fig assignment.
See: http://www.pydev.org/manual_adv_type_hints.html for more details.