I've been trying to change the tick label of my axis. I've imported them from a csv, and have changed the label, but I can't change the tick. I'm just starting out, so if I have any of the terms wrong just let me know. My code is outlined below.
import pandas as pd
import matplotlib.pyplot as plt
data = pd.read_csv ('countries.csv')
uk = data[data.ISO_3_CODE == "GBR"]
plt.plot(uk.date_epicrv)
plt.plot(uk.CumCase)
plt.xlabel('Time')
plt.ylabel("Cumulative infection rate")
plt.show
The csv can be found at https://data.humdata.org/dataset/coronavirus-covid-19-cases-and-deaths if you need it. Sorry I couldn't be more specific, trying to learn a new skill and I believe I'm using the wrong terms to search.
Well, I feel like a fool. I was formatting my graph wrong.
Where I had
plt.plot(uk.date_epicrv)
plt.plot(uk.CumCase)
I should have used
plt.plot(uk.date_epicrv, uk.CumCase)
I was trying to plot both graphs on the x-axis. Closing the question now, hope this helps anyone with the issue down the line.
Related
I'm trying to change the style of sns PairGrid graph. Namely, I want to add a frame around each of the grid graphs. What one graph looks like right now:
How I want it to look:
I've already spent a ton of time reading the documentation and searching the Internet, but I haven't found any suitable answer. Is it even possible with PairGrid?
Thank you all for your help.
Use the despine=False option of PairGrid:
import seaborn as sns
penguins = sns.load_dataset("penguins")
g = sns.PairGrid(penguins, despine=False)
g.map(sns.scatterplot)
Example:
I have some plots generated by matplotlib, which I have been generating using the same code (for different data) for several years. The plots always come out looking normal. This time, I re-ran the same code using different data, and the plots showed up like
(Note that the missing border at the top is the result of my erasing the legend. The problem is the choppy, broken up blue and orange data lines.) Many of the plots generated are broken up like this, but not all are. All were normal the previous times that I ran this code.
I have no idea what's going on to make the lines all broken up like this. I tried re-starting my computer and it didn't help. I can't seem to find anything online about this issue. Does anyone have any idea what's going on here?
Here's the code that generated it (excerpted)
`
import matplotlib
from numpy import NaN
matplotlib.use('Agg')
from matplotlib import pyplot as plt
from PyPDF2 import PdfFileMerger, PdfFileReader
for chan in channels:
dProd.plot(x='Date',y=[a_chan,b_chan],secondary_y=b_chan)
plt.title(chan).get_figure().savefig(folder+'\\'+prod+'\\plots\\'+chan+'.pdf')
plt.close('all')
`
I'm using mplfinance module to plot candlesticks. The problem is mplfinance uses too much memory when it generates plots. I have tried the instructions mentioned in free up the memory used by matplotlib but nothing changed and my code is still fulling up my computer memory.Here is my code:
fig, axlist = mpf.plot(hloc,hlines=hlines,
ylabel='Price(USDT)',type='candle',
style='binance',title=my_title,closefig=True,returnfig=True)
any suggestion is highly appreciated.
It would be helpful to see the rest of your code, to see how you are displaying plots and how many. That said, given the above code, when you are done with each plot you might try:
for ax in axlist:
del ax
del fig
This will save memory, but at the expense of some time (which will anyway not be noticeable unless your are making thousands of plots).
If you are saving your plots to image files (instead of displaying to the screen) then matplotlib.use("Agg") may help as well.
I'm creating a plotly chart in jupyter notebook. Because I'm testing some algorithm I want to add data after the initial fig2.show(). But when I update the data and call fig2.show again a new chart is being rendered. How can I update the chart instead of creating a new chart?
This should be an easy task - but it's way to hard to find for me in the documentation.
import plotly.offline as pyo
import plotly.graph_objs as go
import numpy as np
# Set notebook mode to work in offline
pyo.init_notebook_mode()
fig2 = go.Figure(data=go.Scatter(x=moreX2, y=moreY2))
fig2.show()
Then I'm using update:
moreX2.append(2)
moreY2.append(5)
fig2.data[0].update({"x": moreX2, "y": moreY2})
The chart isn't being rerendered and I tried to call fig.show() again, which just creates a new chart.
This answer worked for me, and seems like the ideal answer to this question as well. I've voted to mark this as a duplicate.
To summarize: by wrapping the Figure in a FigureWidget, we can now do exactly what the OP wanted. Although on Colab I did have to give some extra permission by calling the following:
from google.colab import output
output.enable_custom_widget_manager()
I ran into a strange issue today. I stumbled over a package called pandas_profiling, which I think is quite nice. However, after calling the profiling, the plots in my jupyter notebook change.
The axis ticks aren't correct anymore and the whole look is different.
Can you help me out how to get the usual behaviour back?
Thank you in advance,
Schantall
I tried reloading matplotlib.pyplot.
import matplotlib.pyplot as pp
pp.plot(range(10))
enter image description here
Profile:
profile = prof.ProfileReport(df) #df is some pandas dataframe
display(profile)
pp.plot(range(10))
enter image description here
Well, let's first go to the reason why this happens. As we can see in the source code, the package sets the style:
matplotlib.style.use(resource_filename(__name__, "pandas_profiling.mplstyle"))
The next step is to reset the style. You could try the answer from this post:
How to recover matplotlib defaults after setting stylesheet